Backend
This commit is contained in:
@@ -0,0 +1,61 @@
|
||||
# backend/app/routes/tournaments/courts.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}/courts", response_model=list[schemas.CourtSchema])
|
||||
def get_courts(id: str, db: Session = Depends(get_db)):
|
||||
return crud.get_courts(db, id)
|
||||
|
||||
|
||||
@router.post("/{id}/courts", response_model=schemas.CourtSchema)
|
||||
async def create_court(
|
||||
id: str,
|
||||
court: schemas.CourtCreate,
|
||||
db: Session = Depends(get_db),
|
||||
user: str = Depends(get_current_user),
|
||||
):
|
||||
new_court = crud.create_court(db, id, court)
|
||||
if not new_court:
|
||||
raise HTTPException(404, "Tournament not found")
|
||||
|
||||
await send_ws_update(id)
|
||||
return new_court
|
||||
|
||||
|
||||
@router.patch("/{id}/courts", response_model=schemas.TournamentDetail)
|
||||
async def update_courts(
|
||||
id: str,
|
||||
courts: list[str],
|
||||
db: Session = Depends(get_db),
|
||||
user: str = Depends(get_current_user),
|
||||
):
|
||||
t = crud.update_tournament_courts(db, id, courts)
|
||||
if not t:
|
||||
raise HTTPException(404, "Not found")
|
||||
|
||||
await send_ws_update(id)
|
||||
return t
|
||||
|
||||
|
||||
@router.delete("/{id}/courts/{court_id}")
|
||||
async def delete_court(
|
||||
id: str,
|
||||
court_id: int,
|
||||
db: Session = Depends(get_db),
|
||||
user: str = Depends(get_current_user),
|
||||
):
|
||||
success = crud.delete_court(db, id, court_id)
|
||||
if not success:
|
||||
raise HTTPException(404, "Court or Tournament not found")
|
||||
|
||||
await send_ws_update(id)
|
||||
return SUCCESS
|
||||
Reference in New Issue
Block a user