baseball-engine / backend /app /modules /goals /controller.py
github-actions[bot]
Automated Deploy: 3ea2037ab7d55d5b498f7e2ea0336818fc24f725
fe40b87
Raw History Blame Contribute Delete
1.73 kB
"""N16-N19: goals and milestones."""
from typing import Annotated
from uuid import UUID
from fastapi import APIRouter, Depends, Query
from app.common.academy_access import CurrentStaff
from app.common.schemas import Page
from app.core.dependencies import CurrentAccount, CurrentPlayer, Db, Paging
from app.integrations.push import PushClient, get_push_client
from app.modules.goals.schemas import GoalEnvelope, GoalHistoryOut, GoalIn, MilestoneOut, Mode
from app.modules.goals.service import GoalService
router = APIRouter(prefix="/v1", tags=["goals"])
ModeQuery = Annotated[Mode, Query()]
@router.get("/players/{player_id}/goals", response_model=GoalEnvelope)
async def get_goal(player_id: UUID, mode: ModeQuery, account: CurrentAccount, db: Db) -> GoalEnvelope:
return await GoalService(db).current(account, player_id, mode)
@router.put("/players/{player_id}/goals/{mode}", response_model=GoalEnvelope)
async def put_goal(player_id: UUID, mode: Mode, body: GoalIn, staff: CurrentStaff, db: Db,
push: Annotated[PushClient, Depends(get_push_client)]) -> GoalEnvelope:
return await GoalService(db, push).set(staff, player_id, mode, body)
@router.get("/players/{player_id}/goals/history", response_model=Page[GoalHistoryOut])
async def goal_history(player_id: UUID, mode: ModeQuery, account: CurrentAccount, db: Db,
paging: Paging) -> Page[GoalHistoryOut]:
return await GoalService(db).history(account, player_id, mode, paging)
@router.get("/me/milestones", response_model=Page[MilestoneOut])
async def milestones(mode: ModeQuery, player: CurrentPlayer, db: Db, paging: Paging) -> Page[MilestoneOut]:
return await GoalService(db).milestones(player, mode, paging)