from contextlib import asynccontextmanager from fastapi import FastAPI from fastapi.middleware.cors import CORSMiddleware from app.config import CORS_ORIGINS, DEBUG from app.database import create_db_and_tables # Import all models so SQLModel registers them from app.models import ( User, Activity, Zone, ZoneHistory, Friendship, Score, Notification, ) # noqa: F401 from app.routers import auth, users, activities, zones, friends, leaderboard @asynccontextmanager async def lifespan(app: FastAPI): """Startup: create tables. Shutdown: nothing special yet.""" create_db_and_tables() yield app = FastAPI( title="GeoZoner API", version="0.1.0", description="Territorial fitness tracker backend", lifespan=lifespan, ) # --- CORS --- app.add_middleware( CORSMiddleware, allow_origins=CORS_ORIGINS, allow_credentials=True, allow_methods=["*"], allow_headers=["*"], ) # --- Routers --- app.include_router(auth.router) app.include_router(users.router) app.include_router(activities.router) app.include_router(zones.router) app.include_router(friends.router) app.include_router(leaderboard.router) @app.get("/health") def health(): return {"status": "ok"}