2026-01-08 23:34:42 +08:00
|
|
|
|
from app.extensions import client, logger
|
2025-12-28 17:01:42 +08:00
|
|
|
|
from app.config import Config
|
|
|
|
|
|
|
2026-01-08 23:34:42 +08:00
|
|
|
|
def get_announcements(request_data: list):
|
2025-12-28 17:01:42 +08:00
|
|
|
|
if Config.ISTEST_MODE:
|
|
|
|
|
|
return []
|
2026-01-08 23:34:42 +08:00
|
|
|
|
# 记录请求体到日志,请求体中是用户已关闭的公告ID列表
|
|
|
|
|
|
logger.debug("Request body: %s", request_data)
|
|
|
|
|
|
|
2025-12-28 17:01:42 +08:00
|
|
|
|
announcements = list(client.ht_server.announcement.find({}))
|
2026-01-08 23:34:42 +08:00
|
|
|
|
result = []
|
2025-12-28 17:01:42 +08:00
|
|
|
|
for a in announcements:
|
2026-01-08 23:34:42 +08:00
|
|
|
|
# 拷贝并移除 _id 字段,避免 ObjectId 无法序列化
|
|
|
|
|
|
a = dict(a)
|
2025-12-28 17:01:42 +08:00
|
|
|
|
a.pop('_id', None)
|
2026-01-08 23:34:42 +08:00
|
|
|
|
# 如果请求体中包含该公告ID,说明用户已关闭该公告,不返回该公告
|
|
|
|
|
|
if a.get('Id') not in request_data:
|
|
|
|
|
|
result.append(a)
|
|
|
|
|
|
return result
|