File size: 1,732 Bytes
fe40b87
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
"""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)