- 4 nuove tabelle: remission_practice, remission_invoice, remission_ula_employee, remission_document
con cascade delete e FK
- 13 endpoint /api/remission-practices/*:
GET /mine (lista pratiche user + applications CONTRACT_SIGNED ready_to_start)
POST /start (avvia pratica da application_id, richiede schema PUBLISHED)
GET /{id}, PUT /{id} (regime IVA + note)
POST/DELETE /{id}/invoices
POST/DELETE /{id}/ula-employees
PUT/DELETE /{id}/documents/{doc_code}
GET /{id}/gate-check (valida gate rules contro pratica, ritorna totali + checks)
POST /{id}/submit (gate-check obbligatorio, status DRAFT -> SUBMITTED)
- 1 endpoint debug /api/debug/impersonate (sandbox-only, genera JWT per utente
- necessario perche' /v1/user/login del BE Spring esclude ROLE_BENEFICIARY)
- Gate check calcola: totali per categoria, grand_total, max_remission = min(cap_pct*erogato, cap_abs),
remission_due = min(grand_total, max_remission), applica iva_ordinario_imponibile_only
70 lines
1.9 KiB
Python
70 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, practices, debug
|
|
|
|
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.include_router(practices.router)
|
|
app.include_router(debug.router)
|
|
|
|
|
|
@app.get("/", tags=["root"])
|
|
def root():
|
|
return {
|
|
"service": "rendicontazione-api",
|
|
"version": "0.1.0",
|
|
"docs": "/docs",
|
|
"health": "/health",
|
|
}
|