Update main.py
season 5 update; switch POST /players to PUT /players
This commit is contained in:
parent
8b7c81f197
commit
2dc12d352e
28
main.py
28
main.py
@ -31,7 +31,7 @@ logging.basicConfig(
|
||||
app = FastAPI()
|
||||
|
||||
oauth2_scheme = OAuth2PasswordBearer(tokenUrl="token")
|
||||
DEFAULT_SEASON = 4
|
||||
DEFAULT_SEASON = 5
|
||||
SHEETS_AUTH = pygsheets.authorize(service_file='storage/paper-dynasty-service-creds.json', retries=1)
|
||||
|
||||
|
||||
@ -658,6 +658,25 @@ async def v1_teams_post(team: TeamModel, token: str = Depends(oauth2_scheme)):
|
||||
raise HTTPException(status_code=418, detail='Well slap my ass and call me a teapot; I could not save that team')
|
||||
|
||||
|
||||
@app.post('/api/v1/teams/new-season/{new_season}')
|
||||
async def v1_teams_new_season(new_season: int, token: str = Depends(oauth2_scheme)):
|
||||
if not valid_token(token):
|
||||
logging.warning(f'Bad Token: {token}')
|
||||
db.close()
|
||||
raise HTTPException(
|
||||
status_code=401,
|
||||
detail='You are not authorized to post teams. This event has been logged.'
|
||||
)
|
||||
|
||||
r_query = Team.update(ranking=1000, season=new_season, wallet=Team.wallet + 250).execute()
|
||||
current = Current.latest()
|
||||
current.season = new_season
|
||||
current.save()
|
||||
db.close()
|
||||
|
||||
return {'detail': f'Team rankings, season, and wallet updated for season {new_season}'}
|
||||
|
||||
|
||||
@app.post('/api/v1/teams/{team_id}/money/{delta}')
|
||||
async def v1_teams_money_delta(team_id: int, delta: int, token: str = Depends(oauth2_scheme)):
|
||||
if not valid_token(token):
|
||||
@ -1556,8 +1575,8 @@ async def v1_players_patch(
|
||||
)
|
||||
|
||||
|
||||
@app.post('/api/v1/players')
|
||||
async def v1_players_post(players: PlayerModel, token: str = Depends(oauth2_scheme)):
|
||||
@app.put('/api/v1/players')
|
||||
async def v1_players_put(players: PlayerModel, token: str = Depends(oauth2_scheme)):
|
||||
if not valid_token(token):
|
||||
logging.warning(f'Bad Token: {token}')
|
||||
db.close()
|
||||
@ -3059,6 +3078,9 @@ async def v1_results_team_get(
|
||||
|
||||
if season is not None:
|
||||
all_results = all_results.where(Result.season == season)
|
||||
else:
|
||||
all_results = all_results.where(Result.season == this_team.season)
|
||||
|
||||
if week is not None:
|
||||
all_results = all_results.where(Result.week == week)
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user