- 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>
71 lines
2.3 KiB
Python
71 lines
2.3 KiB
Python
import uuid
|
|
|
|
from fastapi import APIRouter, Depends, HTTPException, Query, status
|
|
from sqlalchemy.ext.asyncio import AsyncSession
|
|
|
|
from app.crud import crud_championship
|
|
from app.database import get_db
|
|
from app.dependencies import get_approved_user, get_organizer
|
|
from app.models.user import User
|
|
from app.schemas.championship import ChampionshipCreate, ChampionshipOut, ChampionshipUpdate
|
|
|
|
router = APIRouter()
|
|
|
|
|
|
@router.get("", response_model=list[ChampionshipOut])
|
|
async def list_championships(
|
|
status: str | None = Query(None),
|
|
skip: int = 0,
|
|
limit: int = 50,
|
|
_user: User = Depends(get_approved_user),
|
|
db: AsyncSession = Depends(get_db),
|
|
):
|
|
return await crud_championship.list_all(db, status=status, skip=skip, limit=limit)
|
|
|
|
|
|
@router.get("/{champ_id}", response_model=ChampionshipOut)
|
|
async def get_championship(
|
|
champ_id: uuid.UUID,
|
|
_user: User = Depends(get_approved_user),
|
|
db: AsyncSession = Depends(get_db),
|
|
):
|
|
champ = await crud_championship.get(db, champ_id)
|
|
if not champ:
|
|
raise HTTPException(status_code=404, detail="Championship not found")
|
|
return champ
|
|
|
|
|
|
@router.post("", response_model=ChampionshipOut, status_code=status.HTTP_201_CREATED)
|
|
async def create_championship(
|
|
data: ChampionshipCreate,
|
|
user: User = Depends(get_organizer),
|
|
db: AsyncSession = Depends(get_db),
|
|
):
|
|
org_id = user.organization.id if user.organization else None
|
|
return await crud_championship.create(db, data, org_id=org_id)
|
|
|
|
|
|
@router.patch("/{champ_id}", response_model=ChampionshipOut)
|
|
async def update_championship(
|
|
champ_id: uuid.UUID,
|
|
data: ChampionshipUpdate,
|
|
_user: User = Depends(get_organizer),
|
|
db: AsyncSession = Depends(get_db),
|
|
):
|
|
champ = await crud_championship.get(db, champ_id)
|
|
if not champ:
|
|
raise HTTPException(status_code=404, detail="Championship not found")
|
|
return await crud_championship.update(db, champ, data)
|
|
|
|
|
|
@router.delete("/{champ_id}", status_code=status.HTTP_204_NO_CONTENT)
|
|
async def delete_championship(
|
|
champ_id: uuid.UUID,
|
|
_user: User = Depends(get_organizer),
|
|
db: AsyncSession = Depends(get_db),
|
|
):
|
|
champ = await crud_championship.get(db, champ_id)
|
|
if not champ:
|
|
raise HTTPException(status_code=404, detail="Championship not found")
|
|
await crud_championship.delete(db, champ)
|