File size: 1,400 Bytes
fe40b87
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
"""N06 to N09: /notifications."""

from uuid import UUID

from fastapi import APIRouter, Response

from app.common.schemas import Page
from app.core.dependencies import CurrentAccount, Db, Paging
from app.modules.notifications.schemas import NotificationOut, ReadAllIn, UnreadCount
from app.modules.notifications.service import NotificationService

router = APIRouter(prefix="/v1", tags=["notifications"])


@router.get("/notifications", response_model=Page[NotificationOut])
async def list_notifications(account: CurrentAccount, db: Db, paging: Paging) -> Page[NotificationOut]:
    return await NotificationService(db).list(account, paging)


@router.get("/notifications/unread-count", response_model=UnreadCount)
async def unread_count(account: CurrentAccount, db: Db) -> UnreadCount:
    return await NotificationService(db).unread_count(account)


@router.post("/notifications/read-all", status_code=204)
async def read_all(account: CurrentAccount, db: Db, body: ReadAllIn | None = None) -> Response:
    await NotificationService(db).mark_all_read(account, body.through if body else None)
    return Response(status_code=204)


@router.post("/notifications/{notification_id}/read", status_code=204)
async def read_one(notification_id: UUID, account: CurrentAccount, db: Db) -> Response:
    await NotificationService(db).mark_read(account, notification_id)
    return Response(status_code=204)