- Create organizations table with Alembic migration (3-phase: create table, migrate data, drop old column) - Add org_id FK on championships linking to organizations - Refactor all schemas into one-class-per-file packages (auth, championship, organization, participant, registration, user) - Update CRUD layer with selectinload for organization relationships - Update frontend types and components to use nested organization object - Remove phantom Championship fields (subtitle, venue, accent_color) from frontend Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
46 lines
1.3 KiB
Python
46 lines
1.3 KiB
Python
import json
|
|
import uuid
|
|
from datetime import datetime
|
|
|
|
from pydantic import BaseModel, model_validator
|
|
|
|
from app.schemas.organization import OrganizationBrief
|
|
|
|
|
|
class ChampionshipOut(BaseModel):
|
|
model_config = {"from_attributes": True}
|
|
|
|
id: uuid.UUID
|
|
org_id: uuid.UUID | None = None
|
|
title: str
|
|
description: str | None
|
|
location: str | None
|
|
event_date: datetime | None
|
|
registration_open_at: datetime | None
|
|
registration_close_at: datetime | None
|
|
form_url: str | None
|
|
entry_fee: float | None
|
|
video_max_duration: int | None
|
|
judges: list[dict] | None
|
|
categories: list[str] | None
|
|
status: str
|
|
source: str
|
|
instagram_media_id: str | None
|
|
image_url: str | None
|
|
organization: OrganizationBrief | None = None
|
|
created_at: datetime
|
|
updated_at: datetime
|
|
|
|
@model_validator(mode="before")
|
|
@classmethod
|
|
def parse_json_fields(cls, v):
|
|
# judges and categories are stored as JSON strings in the DB
|
|
if hasattr(v, "__dict__"):
|
|
raw_j = getattr(v, "judges", None)
|
|
raw_c = getattr(v, "categories", None)
|
|
if isinstance(raw_j, str):
|
|
v.__dict__["judges"] = json.loads(raw_j)
|
|
if isinstance(raw_c, str):
|
|
v.__dict__["categories"] = json.loads(raw_c)
|
|
return v
|