A7 scripts/seed_sandbox.py: - ensure_assigned_application() popola gepafin_schema.assigned_applications - scenario napoli-sas-multi: tranche 1 APPROVED + tranche 2 DRAFT vuota Tranche 1 caso reale Cecilia: 1 fattura B3 524.50 EUR con rettifica 57.36 EUR (storno assicurazione), ammesso 467.14 EUR. 1 ULA T_IND AMMESSA. 4 documenti VALIDO. 2 custom_checks VALIDO (antiriciclaggio + polizza con PDF). Tranche 2 DRAFT: assigned_instructor_id=NULL (simula workflow capo) - TRUNCATE include remission_custom_check_value (CASCADE gia la gestiva) main.py: include router custom_checks + assignment, version bump 0.4.0 Test: seed --reset --scenario=napoli-sas-multi -> 2 tranche create in 6s, PDF polizza 10KB generato in custom_checks/<T1>/polizza_fidejussoria/.
76 lines
2.2 KiB
Python
76 lines
2.2 KiB
Python
"""
|
|
rendicontazione-api — microservizio sviluppato da BFLOWS per Gepafin.
|
|
Gestisce schemi di rendicontazione per bando, pratiche di rendicontazione,
|
|
fatture, ULA, soccorso istruttorio, upload file, verbale istruttoria.
|
|
|
|
Stack: FastAPI + SQLAlchemy + PostgreSQL (schema gepafin_rendic) + weasyprint.
|
|
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 .migrations import run_migrations
|
|
from .routers import health, schemas, practices, debug, instructor, files, verbale, custom_checks, assignment
|
|
|
|
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")
|
|
try:
|
|
with engine.begin() as conn:
|
|
conn.execute(text(f'CREATE SCHEMA IF NOT EXISTS {settings.db_schema}'))
|
|
Base.metadata.create_all(bind=engine)
|
|
run_migrations(engine)
|
|
log.info(f"Schema '{settings.db_schema}' + tabelle + migrations OK")
|
|
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.4.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.include_router(practices.router)
|
|
app.include_router(debug.router)
|
|
app.include_router(instructor.router)
|
|
app.include_router(files.router)
|
|
app.include_router(verbale.router)
|
|
app.include_router(custom_checks.router)
|
|
app.include_router(assignment.router)
|
|
|
|
|
|
@app.get("/", tags=["root"])
|
|
def root():
|
|
return {
|
|
"service": "rendicontazione-api",
|
|
"version": "0.4.0",
|
|
"docs": "/docs",
|
|
"health": "/health",
|
|
}
|