"""E1, E2: drill set logs.""" from datetime import date from typing import Annotated from fastapi import APIRouter, Header, Query from app.common.schemas import Items from app.core.dependencies import CurrentAccount, Db from app.modules.drills.schemas import DrillLogEnvelope, DrillLogIn, DrillLogOut from app.modules.drills.service import DrillLogService from app.modules.idempotency.service import run_idempotent router = APIRouter(prefix="/v1", tags=["drills"]) @router.post("/drill-logs", status_code=201, response_model=DrillLogEnvelope) async def create_drill_log( body: DrillLogIn, account: CurrentAccount, db: Db, idempotency_key: Annotated[str | None, Header(max_length=128)] = None, ): service = DrillLogService(db) async def handler() -> DrillLogEnvelope: return DrillLogEnvelope(log=await service.create(account, body)) return await run_idempotent(db, account.id, idempotency_key, body, handler, status_code=201) @router.get("/drill-logs", response_model=Items[DrillLogOut]) async def list_drill_logs( account: CurrentAccount, db: Db, start: Annotated[date, Query(alias="from")], end: Annotated[date, Query(alias="to")], ) -> Items[DrillLogOut]: return await DrillLogService(db).list(account, start, end)