39 lines
1.1 KiB
Python
39 lines
1.1 KiB
Python
from typing import Optional
|
|
|
|
from fastapi import APIRouter, Depends, Header
|
|
from sqlalchemy.orm import Session
|
|
|
|
from app.core.response import success_response
|
|
from app.db import get_db_session
|
|
from app.services.auth_service import AuthService
|
|
from app.services.notification_service import NotificationService
|
|
|
|
router = APIRouter(prefix="/notifications", tags=["notifications"])
|
|
|
|
|
|
def get_notification_service(db: Session = Depends(get_db_session)) -> NotificationService:
|
|
return NotificationService(db)
|
|
|
|
|
|
def require_current_user(
|
|
authorization: Optional[str] = Header(default=None),
|
|
db: Session = Depends(get_db_session),
|
|
):
|
|
return AuthService(db).require_current_user(authorization)
|
|
|
|
|
|
@router.get("")
|
|
def list_notifications(
|
|
limit: int = 20,
|
|
scope: str = "mine",
|
|
notification_service: NotificationService = Depends(get_notification_service),
|
|
current_user: dict = Depends(require_current_user),
|
|
):
|
|
return success_response(
|
|
notification_service.list_notifications(
|
|
current_user=current_user,
|
|
limit=limit,
|
|
scope=scope,
|
|
)
|
|
)
|