mirror of
https://github.com/DrizzleTime/Foxel.git
synced 2026-07-11 23:43:29 +08:00
feat: add notices feature with API, database model, and UI integration
This commit is contained in:
36
domain/notices/api.py
Normal file
36
domain/notices/api.py
Normal file
@@ -0,0 +1,36 @@
|
||||
from typing import Annotated
|
||||
|
||||
from fastapi import APIRouter, Depends, Query
|
||||
|
||||
from api.response import success
|
||||
from domain.auth import User, get_current_active_user
|
||||
|
||||
from .service import NoticeService
|
||||
|
||||
router = APIRouter(prefix="/api/notices", tags=["notices"])
|
||||
|
||||
|
||||
@router.get("")
|
||||
async def list_notices(
|
||||
current_user: Annotated[User, Depends(get_current_active_user)],
|
||||
page: int = Query(1, ge=1),
|
||||
):
|
||||
data = await NoticeService.list_notices(page=page)
|
||||
return data.model_dump()
|
||||
|
||||
|
||||
@router.get("/popup")
|
||||
async def get_popup_notice(
|
||||
current_user: Annotated[User, Depends(get_current_active_user)],
|
||||
):
|
||||
item = await NoticeService.get_popup_notice()
|
||||
return success(item.model_dump() if item else None)
|
||||
|
||||
|
||||
@router.post("/{notice_id}/dismiss")
|
||||
async def dismiss_popup_notice(
|
||||
notice_id: int,
|
||||
current_user: Annotated[User, Depends(get_current_active_user)],
|
||||
):
|
||||
await NoticeService.dismiss_popup(notice_id)
|
||||
return success()
|
||||
Reference in New Issue
Block a user