Files
Snap.Server/services/announcement_service.py
2026-02-03 12:12:45 +08:00

26 lines
879 B
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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