github-actions[bot]
Automated Deploy: 3ea2037ab7d55d5b498f7e2ea0336818fc24f725
fe40b87
Raw History Blame Contribute Delete
2.27 kB
"""N37-N39 academy reporting and N49-N50 consent records."""
from typing import Annotated
from uuid import UUID
from fastapi import APIRouter, Depends, Header, Query
from fastapi.responses import JSONResponse
from app.common.academy_access import CurrentAdmin
from app.core.dependencies import Db, Paging, Storage
from app.modules.idempotency.service import run_idempotent
from app.modules.reporting.schemas import (
ConsentExportRequest,
ConsentPage,
CorporateResponse,
DashboardResponse,
EarningsResponse,
ExportResponse,
)
from app.modules.reporting.service import ReportingService
router = APIRouter(prefix="/v1/academy", tags=["reporting"])
def get_reporting_service(db: Db, storage: Storage) -> ReportingService:
return ReportingService(db, storage)
Service = Annotated[ReportingService, Depends(get_reporting_service)]
Month = Annotated[str | None, Query()]
@router.get("/dashboard", response_model=DashboardResponse)
async def dashboard(staff: CurrentAdmin, service: Service, month: Month = None) -> DashboardResponse:
return await service.dashboard(staff, month)
@router.get("/earnings", response_model=EarningsResponse)
async def earnings(staff: CurrentAdmin, service: Service, month: Month = None) -> EarningsResponse:
return await service.earnings(staff, month)
@router.get("/corp", response_model=CorporateResponse)
async def corporate(staff: CurrentAdmin, service: Service, month: Month = None) -> CorporateResponse:
await service.corporate(staff)
raise AssertionError("unreachable")
@router.get("/consent", response_model=ConsentPage)
async def consent(staff: CurrentAdmin, service: Service, paging: Paging,
group_id: UUID | None = None) -> ConsentPage:
return await service.consent(staff, group_id, paging.limit, paging.cursor)
@router.post("/consent/export", response_model=ExportResponse, status_code=201)
async def export_consent(
body: ConsentExportRequest, staff: CurrentAdmin, service: Service, db: Db,
idempotency_key: Annotated[str | None, Header(max_length=128)] = None,
) -> JSONResponse:
return await run_idempotent(db, staff.id, idempotency_key, body, lambda: service.export_consent(staff, body),
status_code=201)