Spaces:
Running on T4
Running on T4
Download backend/app/modules/assignments/controller.py from modventures/baseball-engine: direct link, hf CLI and curl.
- Browser
- Download file 2.31 kB
-
https://huggingface.co/spaces/modventures/baseball-engine/resolve/main/backend/app/modules/assignments/controller.py
- Command line
-
hf download hf://spaces/modventures/baseball-engine/backend/app/modules/assignments/controller.py
-
curl -L -o controller.py https://huggingface.co/spaces/modventures/baseball-engine/resolve/main/backend/app/modules/assignments/controller.py
2.31 kB
| """N20-N22: drill assignments and set completion.""" | |
| from typing import Annotated, Literal | |
| from uuid import UUID | |
| from fastapi import APIRouter, Depends, Header, Query | |
| from app.common.academy_access import CurrentStaff | |
| from app.core.dependencies import CurrentAccount, CurrentPlayer, Db, Paging, Storage | |
| from app.integrations.push import PushClient, get_push_client | |
| from app.modules.assignments.schemas import AssignIn, AssignmentEnvelope, AssignmentPage, Mode, SetIn, SetResult | |
| from app.modules.assignments.service import AssignmentService | |
| from app.modules.idempotency.service import run_idempotent | |
| router = APIRouter(prefix="/v1", tags=["assignments"]) | |
| async def list_assignments( | |
| mode: Annotated[Mode, Query()], account: CurrentAccount, db: Db, storage: Storage, paging: Paging, | |
| player_id: UUID | None = None, status: Literal["open", "completed", "all"] = "all", | |
| ) -> AssignmentPage: | |
| return await AssignmentService(db, storage).list(account, mode, player_id, status, paging) | |
| async def assign_drill( | |
| player_id: UUID, body: AssignIn, staff: CurrentStaff, db: Db, storage: Storage, | |
| push: Annotated[PushClient, Depends(get_push_client)], | |
| idempotency_key: Annotated[str | None, Header(max_length=128)] = None, | |
| ): | |
| service = AssignmentService(db, storage, push) | |
| async def handler() -> AssignmentEnvelope: | |
| return AssignmentEnvelope(assignment=await service.assign(staff, player_id, body)) | |
| return await run_idempotent(db, staff.id, idempotency_key, body, handler, status_code=201, scope=player_id) | |
| async def log_set( | |
| assignment_id: UUID, body: SetIn, player: CurrentPlayer, db: Db, storage: Storage, | |
| idempotency_key: Annotated[str | None, Header(max_length=128)] = None, | |
| ): | |
| service = AssignmentService(db, storage) | |
| async def handler() -> SetResult: | |
| return await service.log_set(player, assignment_id, body) | |
| return await run_idempotent(db, player.id, idempotency_key, body, handler, status_code=201, | |
| scope=assignment_id) | |