feat: add admin/notifications
This commit is contained in:
parent
8e0d0a41a3
commit
d4ec293d70
|
|
@ -20,6 +20,9 @@ from domains.admin.service import (
|
||||||
)
|
)
|
||||||
from domains.users.repo import get_all_users
|
from domains.users.repo import get_all_users
|
||||||
|
|
||||||
|
from domains.notifications.schemas import NotificationResponse
|
||||||
|
from domains.notifications.repo import get_all_notifications
|
||||||
|
|
||||||
|
|
||||||
router = APIRouter(
|
router = APIRouter(
|
||||||
prefix="/admin",
|
prefix="/admin",
|
||||||
|
|
@ -105,3 +108,10 @@ async def list_groups(
|
||||||
admin=Depends(get_current_admin)
|
admin=Depends(get_current_admin)
|
||||||
):
|
):
|
||||||
return await get_all_groups(db)
|
return await get_all_groups(db)
|
||||||
|
|
||||||
|
@router.get("/notifications", response_model=list[NotificationResponse])
|
||||||
|
async def list_notifications(
|
||||||
|
db: AsyncSession = Depends(get_db),
|
||||||
|
admin=Depends(get_current_admin)
|
||||||
|
):
|
||||||
|
return await get_all_notifications(db)
|
||||||
|
|
|
||||||
|
|
@ -24,6 +24,13 @@ async def get_user_notifications(db: AsyncSession, user_id: uuid.UUID):
|
||||||
)
|
)
|
||||||
return result.scalars().all()
|
return result.scalars().all()
|
||||||
|
|
||||||
|
async def get_all_notifications(db: AsyncSession):
|
||||||
|
result = await db.execute(
|
||||||
|
select(Notification)
|
||||||
|
.order_by(Notification.created_at.desc())
|
||||||
|
)
|
||||||
|
return result.scalars().all()
|
||||||
|
|
||||||
async def update_notification(db: AsyncSession, notification: Notification):
|
async def update_notification(db: AsyncSession, notification: Notification):
|
||||||
await db.commit()
|
await db.commit()
|
||||||
await db.refresh(notification)
|
await db.refresh(notification)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user