teecup/app/main.py
Erol Haagenrud f740814833 Order of Merit: offentlig/delt visning (ADR-076)
Siste av de tre gjenstående OOM-punktene fra ADR-043 (lag-OOM ADR-074,
eclectic på tvers av turneringer ADR-075, offentlig visning her).

Migrasjon 076: SECURITY DEFINER-bro public_order_of_merit_by_id, samme
anti-enumerering som public_org_by_slug/public_tournament_by_code. Ny
/public/order-of-merits/{id}-endepunkt (gjenbruker den eksisterende
leaderboard-beregningen direkte). Ny uautentisert frontend-side
modellert på public-club.tsx, "Del offentlig lenke" i innstillinger.

83/83 backend-tester, 45/45 vitest, scratch-verifisert i egen inkognito-
nettleserkontekst (ingen session-cookie). Migrasjon vist og bekreftet
før kjøring mot ekte teecup_db. Rullet ut.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
2026-08-15 21:20:23 +02:00

72 lines
1.8 KiB
Python

"""
TeeCup API.
App-factory + livssyklus. All forretningslogikk ligger i app/routers/ — hver
rute der følger samme mønster: Depends(get_authorized_org) verifiserer
medlemskap, org_connection(organization_id) setter RLS-konteksten lokalt for
transaksjonen. Se ARCHITECTURE_DECISIONS.md (ADR-001…014) for reglene bak.
Kjøres i app-containeren (FastAPI + asyncpg + uvicorn):
uvicorn app.main:app --host 0.0.0.0 --port 8000
"""
from contextlib import asynccontextmanager
from fastapi import FastAPI
from .db import init_pool, close_pool
from .routers import (
auth,
courses,
friends,
individual_tournaments,
matches,
messaging,
notifications,
order_of_merit,
organizations,
players,
registration,
round_messages,
rounds,
scoring,
tournaments,
)
from . import storage
@asynccontextmanager
async def lifespan(app: FastAPI):
await init_pool()
await storage.ensure_bucket()
try:
yield
finally:
await close_pool()
app = FastAPI(title="TeeCup API", lifespan=lifespan)
app.include_router(auth.router)
app.include_router(organizations.router)
app.include_router(players.router)
app.include_router(courses.router)
app.include_router(tournaments.router)
app.include_router(individual_tournaments.router)
app.include_router(order_of_merit.router)
app.include_router(order_of_merit.public_router)
app.include_router(matches.router)
app.include_router(scoring.router)
app.include_router(registration.router)
app.include_router(registration.org_router)
app.include_router(messaging.router)
app.include_router(messaging.public_router)
app.include_router(rounds.router)
app.include_router(round_messages.router)
app.include_router(friends.router)
app.include_router(notifications.router)
@app.get("/health")
async def health() -> dict[str, str]:
return {"status": "ok"}