Full-stack mobile app for pole dance championship management. Backend: FastAPI + SQLAlchemy 2 (async) + SQLite (dev) / PostgreSQL (prod) - JWT auth with refresh token rotation - Championship CRUD with Instagram Graph API sync (APScheduler) - Registration flow with status management - Participant list publish with Expo push notifications - Alembic migrations, pytest test suite Mobile: React Native + Expo (TypeScript) - Auth gate: pending approval screen for new members - Championships list & detail screens - Registration form with status tracking - React Query + Zustand + React Navigation v6 Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
71 lines
2.4 KiB
Python
71 lines
2.4 KiB
Python
import uuid
|
|
|
|
from fastapi import APIRouter, Depends, HTTPException, status
|
|
from sqlalchemy.ext.asyncio import AsyncSession
|
|
|
|
from app.crud import crud_championship
|
|
from app.database import get_db
|
|
from app.dependencies import get_admin, get_approved_user, get_organizer
|
|
from app.models.user import User
|
|
from app.schemas.championship import ChampionshipCreate, ChampionshipOut, ChampionshipUpdate
|
|
|
|
router = APIRouter(prefix="/championships", tags=["championships"])
|
|
|
|
|
|
@router.get("", response_model=list[ChampionshipOut])
|
|
async def list_championships(
|
|
status: str | None = None,
|
|
skip: int = 0,
|
|
limit: int = 20,
|
|
_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("/{championship_id}", response_model=ChampionshipOut)
|
|
async def get_championship(
|
|
championship_id: str,
|
|
_user: User = Depends(get_approved_user),
|
|
db: AsyncSession = Depends(get_db),
|
|
):
|
|
champ = await crud_championship.get(db, championship_id)
|
|
if not champ:
|
|
raise HTTPException(status_code=status.HTTP_404_NOT_FOUND)
|
|
return champ
|
|
|
|
|
|
@router.post("", response_model=ChampionshipOut, status_code=status.HTTP_201_CREATED)
|
|
async def create_championship(
|
|
body: ChampionshipCreate,
|
|
_organizer: User = Depends(get_organizer),
|
|
db: AsyncSession = Depends(get_db),
|
|
):
|
|
return await crud_championship.create(db, **body.model_dump(), source="manual")
|
|
|
|
|
|
@router.patch("/{championship_id}", response_model=ChampionshipOut)
|
|
async def update_championship(
|
|
championship_id: str,
|
|
body: ChampionshipUpdate,
|
|
_organizer: User = Depends(get_organizer),
|
|
db: AsyncSession = Depends(get_db),
|
|
):
|
|
champ = await crud_championship.get(db, championship_id)
|
|
if not champ:
|
|
raise HTTPException(status_code=status.HTTP_404_NOT_FOUND)
|
|
updates = {k: v for k, v in body.model_dump().items() if v is not None}
|
|
return await crud_championship.update(db, champ, **updates)
|
|
|
|
|
|
@router.delete("/{championship_id}", status_code=status.HTTP_204_NO_CONTENT)
|
|
async def delete_championship(
|
|
championship_id: str,
|
|
_admin: User = Depends(get_admin),
|
|
db: AsyncSession = Depends(get_db),
|
|
):
|
|
champ = await crud_championship.get(db, championship_id)
|
|
if not champ:
|
|
raise HTTPException(status_code=status.HTTP_404_NOT_FOUND)
|
|
await crud_championship.delete(db, champ)
|