From 2717338958aa27af7038f66a7d0a9b00c30749ee Mon Sep 17 00:00:00 2001 From: KozielGPC Date: Sun, 18 Jun 2023 18:57:33 -0300 Subject: [PATCH] #103 - removendo codigo nao utilizado --- backend/api/routers/matches_routes.py | 89 +++++++++------------------ 1 file changed, 30 insertions(+), 59 deletions(-) diff --git a/backend/api/routers/matches_routes.py b/backend/api/routers/matches_routes.py index c71ee4a..c6e513e 100644 --- a/backend/api/routers/matches_routes.py +++ b/backend/api/routers/matches_routes.py @@ -1,12 +1,7 @@ from typing import List from api.database.config import Session, engine -from api.schemas.matches import ( - Response, - MatchInput, - MatchSchema, - MatchUpdateRequest -) +from api.schemas.matches import Response, MatchInput, MatchSchema, MatchUpdateRequest from api.models.matches import Match from api.models.championships import Championship from api.models.teams import Team @@ -34,7 +29,6 @@ response_description="Sucesso de resposta da aplicação.", ) async def getAll( - id: int = None, championship_id: int = None, team_1_id: int = None, @@ -53,17 +47,17 @@ async def getAll( if championship_id is not None: query = query.filter(Match.championship_id == championship_id) if team_1_id is not None: - query = query.filter(Match.team_1_id == team_1_id) + query = query.filter(Match.team_1_id == team_1_id) if team_2_id is not None: - query = query.filter(Match.team_2_id == team_2_id) + query = query.filter(Match.team_2_id == team_2_id) if winner_team_id is not None: - query = query.filter(Match.winner_team_id == winner_team_id) + query = query.filter(Match.winner_team_id == winner_team_id) if result is not None: - query = query.filter(func.lower(Match.result).like(f"%{result.lower()}%")) + query = query.filter(func.lower(Match.result).like(f"%{result.lower()}%")) if round is not None: - query = query.filter(Match.round == round) + query = query.filter(Match.round == round) if bracket is not None: - query = query.filter(Match.bracket == bracket) + query = query.filter(Match.bracket == bracket) Matches = query.offset(skip).limit(limit).all() @@ -77,39 +71,15 @@ async def getAll( ) async def getById(id: int): match = ( - session.query(Match).options(joinedload(Match.team_1_id), joinedload(Match.team_2_id)). - filter(Match.id == id). - first() + session.query(Match) + .options(joinedload(Match.team_1_id), joinedload(Match.team_2_id)) + .filter(Match.id == id) + .first() ) if match == None: raise HTTPException(status_code=404, detail="Match not found") return jsonable_encoder(match) -#@router.get( -# "/championship/{championship_id}", -# response_model=List[MatchSchema], -# response_description="Sucesso de resposta da aplicação." -#) -#async def getByChampionshipId(championship_id: int, skip: int = 0, limit: int = 100): -# championship = session.query(Championship).filter(Championship.id == championship_id).first() - -# if championship is None: -# raise HTTPException(status_code=404, detail="Championship not found") - -# matches = ( -# session.query(Match) -# .filter(Match.championship_id == championship_id) -# .offset(skip) -# .limit(limit) -# .all() -# ) - -# if not matches: -# raise HTTPException(status_code=404, detail="Matches not found") - -# return matches - - @router.post( "/create", @@ -131,7 +101,7 @@ async def create(data: MatchInput, token: Annotated[str, Depends(oauth2_scheme)] championship = session.query(Championship).filter(Championship.id == data.championship_id).first() if championship == None: raise HTTPException(status_code=404, detail="Championship not found") - + match_input = Match( id=data.id, championship_id=data.championship_id, @@ -140,7 +110,7 @@ async def create(data: MatchInput, token: Annotated[str, Depends(oauth2_scheme)] winner_team_id=data.winner_team_id, bracket=data.bracket, round=data.round, - result=data.result + result=data.result, ) session.add(match_input) session.commit() @@ -153,18 +123,19 @@ async def create(data: MatchInput, token: Annotated[str, Depends(oauth2_scheme)] "winner_team_id": match_input.winner_team_id, "bracket": match_input.bracket, "round": match_input.round, - "result": match_input.result + "result": match_input.result, } return jsonable_encoder(response) -#Vou deixar o delete comentado pq o Rafa disse que nao ia precisar, mas se no futuro precisar ja ta pronto -#@router.delete( + +# Vou deixar o delete comentado pq o Rafa disse que nao ia precisar, mas se no futuro precisar ja ta pronto +# @router.delete( # "/delete/{id}", # status_code=200, # response_model=MatchSchema, # response_description="Sucesso de resposta da aplicação.", -#) -#async def delete(id: int): +# ) +# async def delete(id: int): # match = session.query(Match).filter(Match.id == id).first() # if match == None: # raise HTTPException(status_code=404, detail="Match not found") @@ -186,16 +157,16 @@ async def update(id: int, update_request: MatchUpdateRequest, token: Annotated[s match = session.query(Match).filter(Match.id == id).first() if match is None: - raise HTTPException( - status_code=404, detail="Match not found" - ) - #winner round result - venc = session.query(Team).filter(Match.team_1_id == update_request.winner_team_id and Match.team_2_id == update_request.winner_team_id).first() + raise HTTPException(status_code=404, detail="Match not found") + # winner round result + venc = ( + session.query(Team) + .filter(Match.team_1_id == update_request.winner_team_id and Match.team_2_id == update_request.winner_team_id) + .first() + ) if venc is None: - raise HTTPException( - status_code=404, detail="Team not found" - ) - + raise HTTPException(status_code=404, detail="Team not found") + if update_request.result == None: raise HTTPException(status_code=400, detail="Result cannot be None") @@ -203,8 +174,8 @@ async def update(id: int, update_request: MatchUpdateRequest, token: Annotated[s for key, value in update_data.items(): if getattr(match, key) != value: setattr(match, key, value) - + session.commit() session.refresh(match) - return jsonable_encoder(match) \ No newline at end of file + return jsonable_encoder(match)