innercontext/backend/main.py
Piotr Oleszczyk c09acc7c81 refactor: split table models into Base/Table/Public for proper FastAPI serialization
Add ProductBase, ProductPublic, ProductWithInventory and
SkinConditionSnapshotBase, SkinConditionSnapshotPublic. Table models now inherit
from their Base counterpart and override JSON fields with sa_column. All
field_serializer hacks removed; FastAPI response models use the non-table Public
classes so Pydantic coerces raw DB dicts → typed models cleanly. ProductCreate
and SnapshotCreate now simply inherit their respective Base classes.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-02-27 15:37:46 +01:00

38 lines
1.1 KiB
Python

from contextlib import asynccontextmanager
from dotenv import load_dotenv
load_dotenv() # load .env before db.py reads DATABASE_URL
from fastapi import FastAPI # noqa: E402
from fastapi.middleware.cors import CORSMiddleware # noqa: E402
from db import create_db_and_tables # noqa: E402
from innercontext.api import health, inventory, products, routines, skincare # noqa: E402
@asynccontextmanager
async def lifespan(app: FastAPI):
create_db_and_tables()
yield
app = FastAPI(title="innercontext API", lifespan=lifespan, redirect_slashes=False)
app.add_middleware(
CORSMiddleware, # ty: ignore[invalid-argument-type]
allow_origins=["*"],
allow_methods=["*"],
allow_headers=["*"],
)
app.include_router(products.router, prefix="/products", tags=["products"])
app.include_router(inventory.router, prefix="/inventory", tags=["inventory"])
app.include_router(health.router, prefix="/health", tags=["health"])
app.include_router(routines.router, prefix="/routines", tags=["routines"])
app.include_router(skincare.router, prefix="/skincare", tags=["skincare"])
@app.get("/health-check")
def health_check():
return {"status": "ok"}