fix: screen uses court_number, seed resets sequences

This commit is contained in:
Forge
2026-03-19 01:22:12 +08:00
parent 1be2ba729e
commit 7a4c573d1c
2 changed files with 13 additions and 2 deletions

View File

@@ -15,8 +15,11 @@ router = APIRouter(prefix="/screen", tags=["screen"])
@router.get("/court/{court_id}") @router.get("/court/{court_id}")
def get_court_display(court_id: int, db: Session = Depends(get_db)): def get_court_display(court_id: int, db: Session = Depends(get_db)):
"""Full court display data for TV screen""" """Full court display data for TV screen (court_id = court_number)"""
court = db.query(Court).filter(Court.id == court_id).first() # Try by court_number first (friendlier URLs), then by id
court = db.query(Court).filter(Court.court_number == court_id).first()
if not court:
court = db.query(Court).filter(Court.id == court_id).first()
if not court: if not court:
return {"error": "Court not found"} return {"error": "Court not found"}

View File

@@ -23,6 +23,14 @@ def clear_data(db: Session):
db.query(Court).delete() db.query(Court).delete()
db.query(Player).delete() db.query(Player).delete()
db.commit() db.commit()
# Reset sequences
for table in ['players', 'courts', 'bookings', 'matches', 'match_players',
'tournaments', 'tournament_entries', 'tournament_matches']:
try:
db.execute(__import__('sqlalchemy').text(f"ALTER SEQUENCE {table}_id_seq RESTART WITH 1"))
except Exception:
pass
db.commit()
print("Cleared existing data") print("Cleared existing data")