1
This commit is contained in:
@@ -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))
|
||||
|
||||
Reference in New Issue
Block a user