This commit is contained in:
2026-06-16 10:29:42 +08:00
parent 077fd3cdc6
commit c9c41f0183
2 changed files with 11 additions and 7 deletions
+8 -3
View File
@@ -317,16 +317,21 @@ async def list_admin_notifications(
page: int = Query(1, ge=1),
page_size: int = Query(20, ge=1, le=500),
user_id: str | None = Query(None),
is_read: bool = Query(None),
admin: User = Depends(get_admin_user),
db: AsyncSession = Depends(get_db),
):
"""List unread notifications with optional user_id filter."""
query = select(Notification).where(Notification.is_read == False).order_by(Notification.created_at.desc())
count_query = select(func.count(Notification.id)).where(Notification.is_read == False)
"""List all notifications with optional filters."""
query = select(Notification).order_by(Notification.created_at.desc())
count_query = select(func.count(Notification.id))
if user_id:
query = query.where(Notification.user_id == user_id)
count_query = count_query.where(Notification.user_id == user_id)
if is_read is not None:
query = query.where(Notification.is_read == is_read)
count_query = count_query.where(Notification.is_read == is_read)
total = (await db.execute(count_query)).scalar() or 0
result = await db.execute(query.offset((page - 1) * page_size).limit(page_size))
@@ -27,11 +27,10 @@ const NotificationPopup: React.FC = () => {
const fetchNotifications = useCallback(async () => {
try {
const result = await getNotifications();
const result = await getNotifications(1, 20, false);
const data = result.items || [];
const unread = data.filter((n: Notification) => !n.isRead);
setNotifications(unread);
if (unread.length > 0 && !visible) {
setNotifications(data);
if (data.length > 0 && !visible) {
setVisible(true);
setCurrentIndex(0);
}