- 4 nuove colonne su remission_practice: assigned_instructor_id, reviewed_at,
reviewed_by, rejection_reason, approved_remission
- Nuova tabella remission_amendment_request con cascade delete, scope JSONB,
stati AWAITING -> RESPONSE_RECEIVED -> CLOSED / EXPIRED / REJECTED
- Router instructor.py (287 righe) con 8 endpoint:
/queue, /{id}, /{id}/claim, /{id}/approve, /{id}/reject,
/{id}/amendment, /{id}/amendment/{aid}/close,
/{id}/amendment/{aid}/respond-beneficiary
- GET /{id} (router practices) ora include amendments nel payload
- Manager manager_view flag per ROLE_INSTRUCTOR_MANAGER + SUPER_ADMIN
(vede tutto il pool vs solo le proprie assegnazioni)
- Logica status transitions verificata:
SUBMITTED -> UNDER_REVIEW (claim)
UNDER_REVIEW <-> AWAITING_AMENDMENT (amendment open/close)
UNDER_REVIEW | AWAITING_AMENDMENT -> APPROVED | REJECTED
- _compute_gate_check riusato anche dal router istruttore per calcolo
remission_due in coda e nel dettaglio
Test end-to-end verde: ciclo completo benef -> istruttore -> soccorso ->
risposta -> chiusura -> approvazione funzionante su NAPOLI SAS.
71 lines
2.0 KiB
Python
71 lines
2.0 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, instructor
|
|
|
|
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.include_router(instructor.router)
|
|
|
|
|
|
@app.get("/", tags=["root"])
|
|
def root():
|
|
return {
|
|
"service": "rendicontazione-api",
|
|
"version": "0.1.0",
|
|
"docs": "/docs",
|
|
"health": "/health",
|
|
}
|