Backend
This commit is contained in:
@@ -0,0 +1,61 @@
|
||||
# backend/app/routes/tournaments/teams.py
|
||||
|
||||
from fastapi import Depends, HTTPException
|
||||
from sqlalchemy.orm import Session
|
||||
|
||||
from ... import crud, schemas
|
||||
from ...constants import SUCCESS
|
||||
from ...core.websocket_manager import send_ws_update
|
||||
from ...core.auth import get_current_user
|
||||
from ...database import get_db
|
||||
from . import router
|
||||
|
||||
|
||||
@router.get("/{id}/teams", response_model=list[schemas.TeamSchema])
|
||||
def get_teams(id: str, db: Session = Depends(get_db)):
|
||||
return crud.get_teams(db, id)
|
||||
|
||||
|
||||
@router.post("/{id}/teams", response_model=schemas.TeamSchema)
|
||||
async def create_team(
|
||||
id: str,
|
||||
team: schemas.TeamCreate,
|
||||
db: Session = Depends(get_db),
|
||||
user: str = Depends(get_current_user),
|
||||
):
|
||||
new_team = crud.create_team(db, id, team)
|
||||
if not new_team:
|
||||
raise HTTPException(404, "Tournament not found")
|
||||
|
||||
await send_ws_update(id)
|
||||
return new_team
|
||||
|
||||
|
||||
@router.patch("/{id}/teams", response_model=list[schemas.TeamSchema])
|
||||
async def update_teams(
|
||||
id: str,
|
||||
teams: list[str],
|
||||
db: Session = Depends(get_db),
|
||||
user: str = Depends(get_current_user),
|
||||
):
|
||||
t = crud.update_tournament_teams(db, id, teams)
|
||||
if not t:
|
||||
raise HTTPException(404, "Not found")
|
||||
|
||||
await send_ws_update(id)
|
||||
return t.teams
|
||||
|
||||
|
||||
@router.delete("/{id}/teams/{team_id}")
|
||||
async def delete_team(
|
||||
id: str,
|
||||
team_id: int,
|
||||
db: Session = Depends(get_db),
|
||||
user: str = Depends(get_current_user),
|
||||
):
|
||||
success = crud.delete_team(db, id, team_id)
|
||||
if not success:
|
||||
raise HTTPException(404, "Team or Tournament not found")
|
||||
|
||||
await send_ws_update(id)
|
||||
return SUCCESS
|
||||
Reference in New Issue
Block a user