68 lines
1.9 KiB
Python
68 lines
1.9 KiB
Python
"""
|
|
rendicontazione-api — microservizio sviluppato da BFLOWS per Gepafin.
|
|
Gestisce schemi di rendicontazione per bando, pratiche di rendicontazione,
|
|
fatture, ULA, soccorso istruttorio.
|
|
|
|
Stack: FastAPI + SQLAlchemy + PostgreSQL (schema gepafin_rendic).
|
|
Auth: JWT condiviso con GEPAFIN-BE.
|
|
"""
|
|
import logging
|
|
from contextlib import asynccontextmanager
|
|
from fastapi import FastAPI
|
|
from fastapi.middleware.cors import CORSMiddleware
|
|
from sqlalchemy import text
|
|
|
|
from .config import get_settings
|
|
from .db import engine, Base
|
|
from .routers import health, schemas
|
|
|
|
logging.basicConfig(level=logging.INFO, format="%(asctime)s %(levelname)s %(name)s: %(message)s")
|
|
log = logging.getLogger("rendicontazione-api")
|
|
|
|
settings = get_settings()
|
|
|
|
|
|
@asynccontextmanager
|
|
async def lifespan(app: FastAPI):
|
|
log.info("Avvio rendicontazione-api")
|
|
# Crea schema e tabelle se non esistono (bootstrap sandbox)
|
|
try:
|
|
with engine.begin() as conn:
|
|
conn.execute(text(f'CREATE SCHEMA IF NOT EXISTS {settings.db_schema}'))
|
|
Base.metadata.create_all(bind=engine)
|
|
log.info(f"Schema '{settings.db_schema}' e tabelle inizializzate")
|
|
except Exception as e:
|
|
log.error(f"Errore bootstrap DB: {e}")
|
|
raise
|
|
yield
|
|
log.info("Shutdown rendicontazione-api")
|
|
|
|
|
|
app = FastAPI(
|
|
title="rendicontazione-api",
|
|
description="Microservizio rendicontazione per Gepafin — sviluppato da BFLOWS",
|
|
version="0.1.0",
|
|
lifespan=lifespan,
|
|
)
|
|
|
|
app.add_middleware(
|
|
CORSMiddleware,
|
|
allow_origins=settings.cors_list,
|
|
allow_credentials=True,
|
|
allow_methods=["*"],
|
|
allow_headers=["*"],
|
|
)
|
|
|
|
app.include_router(health.router, tags=["health"])
|
|
app.include_router(schemas.router)
|
|
|
|
|
|
@app.get("/", tags=["root"])
|
|
def root():
|
|
return {
|
|
"service": "rendicontazione-api",
|
|
"version": "0.1.0",
|
|
"docs": "/docs",
|
|
"health": "/health",
|
|
}
|