add /wipe/game

This commit is contained in:
Cal Corum 2023-07-29 01:35:39 -05:00
parent 40df835d98
commit 2d235eb6f0
3 changed files with 37 additions and 1 deletions

View File

@ -156,7 +156,7 @@ async def post_decisions(dec_list: DecisionList, token: str = Depends(oauth2_sch
return f'Inserted {len(new_dec)} decisions'
@router.delete('/{decision_id')
@router.delete('/{decision_id}')
async def delete_decision(decision_id: int, token: str = Depends(oauth2_scheme)):
if not valid_token(token):
logging.warning(f'delete_decision - Bad Token: {token}')

View File

@ -139,6 +139,30 @@ async def post_games(game_list: GameList, token: str = Depends(oauth2_scheme)):
return f'Inserted {len(new_games)} games'
@router.post('/wipe/{game_id}')
async def wipe_game(game_id: int, token: str = Depends(oauth2_scheme)):
if not valid_token(token):
logging.warning(f'wipe_game - Bad Token: {token}')
raise HTTPException(status_code=401, detail='Unauthorized')
this_game = StratGame.get_or_none(StratGame.id == game_id)
if not this_game:
db.close()
raise HTTPException(status_code=404, detail=f'StratGame ID {game_id} not found')
this_game.away_score = None
this_game.home_score = None
this_game.game_num = None
if this_game.save() == 1:
g_result = model_to_dict(this_game)
db.close()
return g_result
else:
db.close()
raise HTTPException(status_code=500, detail=f'Unable to wipe game {game_id}')
@router.delete('/{game_id}')
async def delete_game(game_id: int, token: str = Depends(oauth2_scheme)):
if not valid_token(token):

View File

@ -122,6 +122,8 @@ async def get_plays(
batter_pos: list = Query(default=None), catcher_id: list = Query(default=None),
defender_id: list = Query(default=None), runner_id: list = Query(default=None),
offense_team_id: list = Query(default=None), defense_team_id: list = Query(default=None),
double: Optional[int] = None, triple: Optional[int] = None, homerun: Optional[int] = None,
sb: Optional[int] = None, cs: Optional[int] = None,
short_output: Optional[bool] = False, limit: Optional[int] = 200):
all_plays = StratPlay.select()
@ -158,6 +160,16 @@ async def get_plays(
(StratPlay.pitcher_team << all_teams) | (StratPlay.catcher_team << all_teams) |
(StratPlay.defender_team << all_teams)
)
if double is not None:
all_plays = all_plays.where(StratPlay.double == double)
if triple is not None:
all_plays = all_plays.where(StratPlay.triple == triple)
if homerun is not None:
all_plays = all_plays.where(StratPlay.homerun == homerun)
if sb is not None:
all_plays = all_plays.where(StratPlay.sb == sb)
if cs is not None:
all_plays = all_plays.where(StratPlay.cs == cs)
if limit > 5000:
limit = 5000