invix_test_task/api/app/main.py

33 lines
779 B
Python

import logging
from contextlib import asynccontextmanager
from fastapi import FastAPI
from sqlalchemy import text
from app.bootstrap import init_db
from app.db import engine
from app.deps import SessionDep
from app.routers import cart, catalog, internal, orders
logging.basicConfig(level=logging.INFO)
@asynccontextmanager
async def lifespan(_app: FastAPI):
await init_db()
yield
await engine.dispose()
app = FastAPI(title="Shop", lifespan=lifespan)
app.include_router(catalog.router)
app.include_router(cart.router)
app.include_router(orders.router)
app.include_router(internal.router)
@app.get("/health")
async def health(db: SessionDep) -> dict[str, str]:
await db.execute(text("SELECT 1"))
return {"status": "ok"}