Added /teams roster pull
This commit is contained in:
parent
635baa91ad
commit
e687629485
@ -1,5 +1,6 @@
|
||||
from fastapi import APIRouter, Depends, HTTPException, Query
|
||||
from typing import List, Optional
|
||||
from typing import List, Optional, Literal
|
||||
import copy
|
||||
import logging
|
||||
import pydantic
|
||||
|
||||
@ -76,7 +77,43 @@ async def get_one_team(team_id: int):
|
||||
return r_team
|
||||
|
||||
|
||||
@router.get('/{team_id}')
|
||||
@router.get('/{team_id}/roster/{which}')
|
||||
async def get_team_roster(team_id: int, which: Literal['current', 'next'], sort: Optional[str] = None):
|
||||
try:
|
||||
this_team = Team.get_by_id(team_id)
|
||||
except Exception as e:
|
||||
raise HTTPException(status_code=404, detail=f'Team ID {team_id} not found')
|
||||
|
||||
if which == 'current':
|
||||
full_roster = this_team.get_this_week()
|
||||
else:
|
||||
full_roster = this_team.get_next_week()
|
||||
|
||||
active_players = copy.deepcopy(full_roster['active']['players'])
|
||||
sil_players = copy.deepcopy(full_roster['shortil']['players'])
|
||||
lil_players = copy.deepcopy(full_roster['longil']['players'])
|
||||
full_roster['active']['players'] = []
|
||||
full_roster['shortil']['players'] = []
|
||||
full_roster['longil']['players'] = []
|
||||
|
||||
for player in active_players:
|
||||
full_roster['active']['players'].append(model_to_dict(player))
|
||||
for player in sil_players:
|
||||
full_roster['shortil']['players'].append(model_to_dict(player))
|
||||
for player in lil_players:
|
||||
full_roster['longil']['players'].append(model_to_dict(player))
|
||||
|
||||
if sort:
|
||||
if sort == 'wara-desc':
|
||||
full_roster['active']['players'].sort(key=lambda p: p["wara"], reverse=True)
|
||||
full_roster['active']['players'].sort(key=lambda p: p["wara"], reverse=True)
|
||||
full_roster['active']['players'].sort(key=lambda p: p["wara"], reverse=True)
|
||||
|
||||
db.close()
|
||||
return full_roster
|
||||
|
||||
|
||||
@router.patch('/{team_id}')
|
||||
async def patch_team(
|
||||
team_id: int, manager1_id: Optional[int] = None, manager2_id: Optional[int] = None, gmid: Optional[int] = None,
|
||||
gmid2: Optional[int] = None, mascot: Optional[str] = None, stadium: Optional[str] = None,
|
||||
|
||||
Loading…
Reference in New Issue
Block a user