Files
Snap.Server/services/announcement_service.py

26 lines
879 B
Python
Raw Normal View History

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