Better bracket logic
This commit is contained in:
@@ -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.
|
||||
|
||||
Reference in New Issue
Block a user