Added seperate courts
This commit is contained in:
+28
-29
@@ -28,7 +28,7 @@ def create_tournament(db: Session, data: schemas.TournamentCreate):
|
||||
type=data.type,
|
||||
)
|
||||
new_t.teams = [models.Team(name=n) for n in data.teams]
|
||||
new_t.courts = [models.Court(name=n) for n in data.courts]
|
||||
new_t.courts = db.query(models.Court).filter(models.Court.id.in_(data.courts)).all()
|
||||
|
||||
db.add(new_t)
|
||||
db.commit()
|
||||
@@ -141,53 +141,52 @@ def delete_team(db: Session, tournament_id: str, team_id: int):
|
||||
return True
|
||||
|
||||
|
||||
def get_courts(db: Session, tournament_id: str):
|
||||
return (
|
||||
db.query(models.Court).filter(models.Court.tournament_id == tournament_id).all()
|
||||
)
|
||||
def get_courts(db: Session):
|
||||
return db.query(models.Court).all()
|
||||
|
||||
|
||||
def create_court(db: Session, tournament_id: str, court_data: schemas.CourtCreate):
|
||||
t = get_tournament(db, tournament_id)
|
||||
if not t:
|
||||
return None
|
||||
|
||||
new_court = models.Court(name=court_data.name, tournament_id=tournament_id)
|
||||
def create_court(db: Session, court_data: schemas.CourtCreate):
|
||||
new_court = models.Court(name=court_data.name)
|
||||
db.add(new_court)
|
||||
db.flush()
|
||||
|
||||
logic.update_schedule_times(db, t)
|
||||
|
||||
db.commit()
|
||||
db.refresh(new_court)
|
||||
return new_court
|
||||
|
||||
|
||||
def delete_court(db: Session, tournament_id: str, court_id: int):
|
||||
t = get_tournament(db, tournament_id)
|
||||
if not t:
|
||||
return None
|
||||
def delete_court(db: Session, court_id: int):
|
||||
court = db.get(models.Court, court_id)
|
||||
if not court or court.tournament_id != tournament_id:
|
||||
return None
|
||||
if not court:
|
||||
return False
|
||||
|
||||
affected_tournaments = list(court.tournaments)
|
||||
|
||||
matches = db.query(models.Match).filter(models.Match.court_id == court_id).all()
|
||||
for m in matches:
|
||||
if m.status == models.MatchStatus.FINISHED:
|
||||
m.court_id = None
|
||||
else:
|
||||
m.court_id = None
|
||||
m.start_time = None
|
||||
|
||||
db.delete(court)
|
||||
db.flush()
|
||||
|
||||
logic.update_schedule_times(db, t)
|
||||
|
||||
db.commit()
|
||||
|
||||
processed_days = set()
|
||||
for t in affected_tournaments:
|
||||
day = t.timestamp.date() if t.timestamp else None
|
||||
if day and day not in processed_days:
|
||||
logic.update_schedule_times(db, t)
|
||||
processed_days.add(day)
|
||||
|
||||
return True
|
||||
|
||||
|
||||
def update_tournament_courts(
|
||||
db: Session, tournament_id: str, new_court_names: list[str]
|
||||
):
|
||||
def update_tournament_courts(db: Session, tournament_id: str, new_court_ids: list[int]):
|
||||
t = get_tournament(db, tournament_id)
|
||||
if not t:
|
||||
return None
|
||||
|
||||
t.courts = [models.Court(name=c, tournament_id=t.id) for c in new_court_names]
|
||||
t.courts = db.query(models.Court).filter(models.Court.id.in_(new_court_ids)).all()
|
||||
db.flush()
|
||||
logic.update_schedule_times(db, t)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user