120 lines
2.5 KiB
Python
120 lines
2.5 KiB
Python
# backend/app/schemas.py
|
|
from datetime import datetime
|
|
|
|
from pydantic import BaseModel, ConfigDict
|
|
|
|
from .constants import BracketType, MatchSourceType, MatchStatus, TournamentTypes
|
|
|
|
|
|
class TeamSchema(BaseModel):
|
|
id: int
|
|
name: str
|
|
model_config = ConfigDict(from_attributes=True)
|
|
|
|
|
|
class CourtSchema(BaseModel):
|
|
id: int
|
|
name: str
|
|
model_config = ConfigDict(from_attributes=True)
|
|
|
|
|
|
class TeamCreate(BaseModel):
|
|
name: str
|
|
|
|
|
|
class CourtCreate(BaseModel):
|
|
name: str
|
|
|
|
|
|
class SetScore(BaseModel):
|
|
p1: int
|
|
p2: int
|
|
|
|
|
|
class ScoreReport(BaseModel):
|
|
code: str | None = None
|
|
sets: list[SetScore]
|
|
|
|
|
|
class MatchOut(BaseModel):
|
|
id: str
|
|
node_id: str
|
|
status: MatchStatus
|
|
timestamp: datetime | None = None
|
|
court: CourtSchema | None = None
|
|
p1_team: TeamSchema | None = None
|
|
p2_team: TeamSchema | None = None
|
|
winner_team_id: int | None = None
|
|
|
|
sets: list[SetScore] = []
|
|
|
|
model_config = ConfigDict(from_attributes=True)
|
|
|
|
|
|
class BracketNodeOut(BaseModel):
|
|
id: str
|
|
display_number: int
|
|
bracket_type: BracketType
|
|
round_number: int
|
|
planned_start_time: datetime | None = None
|
|
planned_court_id: int | None = None
|
|
source_p1_node_id: str | None = None
|
|
source_p2_node_id: str | None = None
|
|
source_p1_type: MatchSourceType | None = None
|
|
source_p2_type: MatchSourceType | None = None
|
|
winner_next_node_id: str | None = None
|
|
loser_next_node_id: str | None = None
|
|
p1_team: TeamSchema | None = None
|
|
p2_team: TeamSchema | None = None
|
|
match: MatchOut | None = None
|
|
|
|
model_config = ConfigDict(from_attributes=True)
|
|
|
|
|
|
class TournamentCreate(BaseModel):
|
|
name: str
|
|
code: str
|
|
type: TournamentTypes
|
|
timestamp: datetime
|
|
duration: int
|
|
teams: list[str]
|
|
courts: list[str]
|
|
|
|
|
|
class TournamentUpdate(BaseModel):
|
|
name: str | None = None
|
|
code: str | None = None
|
|
timestamp: datetime | None = None
|
|
duration: int | None = None
|
|
type: TournamentTypes | None = None
|
|
|
|
|
|
class TournamentOut(BaseModel):
|
|
id: str
|
|
name: str
|
|
timestamp: datetime
|
|
type: TournamentTypes
|
|
team_count: int
|
|
court_count: int
|
|
model_config = ConfigDict(from_attributes=True)
|
|
|
|
|
|
class TournamentDetail(BaseModel):
|
|
id: str
|
|
name: str
|
|
timestamp: datetime
|
|
type: TournamentTypes
|
|
teams: list[TeamSchema]
|
|
courts: list[CourtSchema]
|
|
|
|
model_config = ConfigDict(from_attributes=True)
|
|
|
|
|
|
class TournamentUpdateResponse(TournamentDetail):
|
|
code: str
|
|
|
|
|
|
class Token(BaseModel):
|
|
access_token: str
|
|
token_type: str
|