Skip to content

Commit

Permalink
#103 - removendo codigo nao utilizado
Browse files Browse the repository at this point in the history
  • Loading branch information
KozielGPC committed Jun 18, 2023
1 parent 81182e3 commit 2717338
Showing 1 changed file with 30 additions and 59 deletions.
89 changes: 30 additions & 59 deletions backend/api/routers/matches_routes.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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,
Expand All @@ -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()

Expand 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",
Expand All @@ -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,
Expand All @@ -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()
Expand All @@ -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")
Expand All @@ -186,25 +157,25 @@ 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")

update_data = update_request.dict(exclude_unset=True)
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)
return jsonable_encoder(match)

0 comments on commit 2717338

Please sign in to comment.