Files
param-hub-python/modules/routes/__pycache__/api_notifications.cpython-310.pyc
T

35 lines
3.7 KiB
Plaintext
Raw Normal View History

o
œ,QjÅã@dZddlZddlZddlmZddlmZmZmZddlm Z ddl
m Z m Z ede
ƒZe dZe d ¡d
dƒZe d ¡d d
ƒZejddgdddƒZejddgdddƒZejddgdddƒZdddZdS)u
é€šçŸ¥ç®¡ç† API
éN)Údatetime)Ú BlueprintÚrequestÚjsonify)ÚDATA_DIR)Ú load_dataÚ save_dataÚapi_notificationsznotifications.jsonz/api/notificationscCs`ttƒ}tj dd¡dk}ttj dd¡ƒ}|rdd|Dƒ}t|dd „d
d }t|d |ƒS)
u获å–通知列表ÚunreadÚlimité2cSóg|]
}| dd¡s|qS©ÚreadF©Úget©Ú.0Úrú:works/param-hub-python/modules/routes/api_notifications.pyÚ
<listcomp>óz%api_notifications.<locals>.<listcomp>cSó | dd¡S©
created_atÚr©ÚxrrrÚ<lambda>ó z#api_notifications.<locals>.<lambda>T©ÚkeyÚreverseN)rÚNOTIFICATIONS_FILErÚargsrÚintÚsortedr)Ú
notificationsÚ unread_onlyr
rrrr sz/api/notifications/unread-countcCs&ttƒ}tdd|Dƒƒ}td|iƒS)uèŽ·å–æœªè¯»é€šçŸ¥æ•°é‡cSrrrrrrrr&rz$api_unread_count.<locals>.<listcomp>Úcount)rr&Úlenr)r*r,rrrÚapi_unread_count"s r.z)/api/notifications/<notification_id>/readÚPOST)Úmethodscsdttƒ}tfdd|Dƒdƒ}|stddiƒdfSd|d<t ¡ d ¡|d
<tt|ƒtd diƒS) u标记通知为已读c3s |] }|dˆkr|VqdS)ÚidNrr©Únotification_idrrÚ <genexpr>.sz api_mark_read.<locals>.<genexpr>NÚerrorzNotification not foundi”Trú%Y-%m-%d %H:%M:%SÚread_atÚsuccess)rr&ÚnextrrÚnowÚstrftimer)r3r*Ú notificationrr2rÚ
api_mark_read*s
 r=z/api/notifications/read-allcCsNttƒ}|D]}| dd¡sd|d<t ¡ d¡|d<qtt|ƒtddiƒS)u标记所有通知为已读rFTr6r7r8)rr&rrr:r;rr)r*rrrrÚapi_mark_all_read7s 
 r>z$/api/notifications/<notification_id>ÚDELETEcs0ttƒ}fdd|Dƒ}tt|ƒtddiƒS)u 删除通知csg|]
}|dˆkr|qS)r1rrr2rrrGrz+api_delete_notification.<locals>.<listcomp>r8T)rr&rr)r3r*rr2rÚapi_delete_notificationCs
 r@ÚinfoÚsystemc
Csxttƒ}t ¡jdd|||||pidt ¡ d¡dœ}| |¡t |ƒdkr5t
|ddd d
dd}t t|ƒ|S)
创建一æ¡é€šçŸ¥
傿•°:
title: 通知标题
message: 通知内容
level: 级别 info/warning/error/success
category: 分类 system/api/review/statistics
data: 附加数æ®(dict)
Fr6)r1ÚtitleÚmessageÚlevelÚcategoryÚdatarrcSrrrrrrrr!jr"z%create_notification.<locals>.<lambda>Tr#) rr&ÚuuidÚuuid4Úhexrr:r;Úappendr-r)r)rDrErFrGrHr*r<rrrÚcreate_notificationNs  ø

rM)rArBN)Ú__doc__rIÚjsonrÚflaskrrrÚconfigrÚutilsrrÚ__name__Únotifications_bpr&Úrouter r.r=r>r@rMrrrrÚ<module>s(