Better bracket logic

This commit is contained in:
2026-02-14 01:04:54 +01:00 Verified
parent 87d3ea5ef0
commit 7b878b3abe
32 changed files with 1326 additions and 1348 deletions
+1 -1
View File
@@ -3,4 +3,4 @@ from fastapi import APIRouter
router = APIRouter(prefix="/tournaments", tags=["Tournaments"])
from . import tournaments, teams, courts, matches, report, bracket
from . import tournaments, teams, courts, matches, report
-15
View File
@@ -1,15 +0,0 @@
# backend/app/routes/tournaments/bracket.py
from fastapi import Depends, HTTPException
from sqlalchemy.orm import Session
from ... import crud, schemas
from ...database import get_db
from . import router
@router.get("/{id}/bracket", response_model=list[schemas.BracketNodeOut])
def get_tournament_bracket(id: str, db: Session = Depends(get_db)):
t = crud.get_tournament(db, id)
if not t:
raise HTTPException(404, "Tournament not found")
return t.nodes
+12 -9
View File
@@ -1,5 +1,5 @@
# backend/app/routes/tournaments/report.py
from typing import List, Optional
from typing import Optional
from fastapi import Depends, HTTPException, Query
from sqlalchemy.orm import Session
@@ -45,7 +45,9 @@ async def report_score(
_apply_score(match, report.sets)
flag_modified(match, "sets")
db.commit()
logic.advance_flow(db, t)
if match.winner_team_id:
logic.advance_winner(db, match, match.winner_team_id)
await send_ws_update(id)
return SUCCESS
@@ -59,11 +61,6 @@ async def edit_score(
db: Session = Depends(get_db),
user: Optional[str] = Depends(get_optional_user),
):
"""
Allows correcting a score.
Note: If the winner changes, 'advance_flow' might need to handle
undoing previous advancements, but for now we just re-run the flow.
"""
t = crud.get_tournament(db, id)
if not t:
raise HTTPException(404, "Tournament not found")
@@ -74,12 +71,16 @@ async def edit_score(
if not match:
raise HTTPException(404, "Match not found")
logic.undo_advancement(db, match)
if report.sets:
_apply_score(match, report.sets)
flag_modified(match, "sets")
db.commit()
logic.advance_flow(db, t)
if match.winner_team_id:
logic.advance_winner(db, match, match.winner_team_id)
await send_ws_update(id)
return SUCCESS
@@ -103,6 +104,8 @@ async def clear_score(
if not match:
raise HTTPException(404, "Match not found")
logic.undo_advancement(db, match)
match.winner_team_id = None
match.status = MatchStatus.PENDING
match.sets = []
@@ -114,7 +117,7 @@ async def clear_score(
return SUCCESS
def _apply_score(match: models.Match, sets: List[schemas.SetScore]):
def _apply_score(match: models.Match, sets: list[schemas.SetScore]):
"""
Calculates winner based on sets and updates the match object.
Does NOT commit to DB.
+1 -1
View File
@@ -6,7 +6,7 @@ from ..core.websocket_manager import manager
router = APIRouter(prefix="/ws", tags=["Websocket"])
@router.websocket("/")
@router.websocket("")
async def websocket_endpoint(websocket: WebSocket):
await manager.connect(websocket)
try: