""" API d'ingestion et d'orchestration pour le pipeline notarial """ from fastapi import FastAPI, UploadFile, File, Form, HTTPException, Depends from fastapi.middleware.cors import CORSMiddleware from fastapi.responses import JSONResponse import uuid import time import os from typing import Optional import logging from domain.database import get_db, init_db from routes import documents, health, admin, notary_documents # Configuration du logging logging.basicConfig(level=logging.INFO) logger = logging.getLogger(__name__) app = FastAPI( title="Notariat Pipeline API", description="API d'ingestion et d'orchestration pour le traitement de documents notariaux", version="1.1.0" ) # Configuration CORS app.add_middleware( CORSMiddleware, allow_origins=["*"], # À restreindre en production allow_credentials=True, allow_methods=["*"], allow_headers=["*"], ) # Inclusion des routes app.include_router(health.router, prefix="/api", tags=["health"]) app.include_router(documents.router, prefix="/api", tags=["documents"]) app.include_router(admin.router, prefix="/api/admin", tags=["admin"]) app.include_router(notary_documents.router, prefix="/api", tags=["notary"]) @app.on_event("startup") async def startup_event(): """Initialisation au démarrage de l'application""" logger.info("Démarrage de l'API Notariat Pipeline") await init_db() @app.on_event("shutdown") async def shutdown_event(): """Nettoyage à l'arrêt de l'application""" logger.info("Arrêt de l'API Notariat Pipeline") @app.exception_handler(Exception) async def global_exception_handler(request, exc): """Gestionnaire d'exceptions global""" logger.error(f"Erreur non gérée: {exc}", exc_info=True) return JSONResponse( status_code=500, content={"detail": "Erreur interne du serveur"} ) @app.get("/") async def root(): """Point d'entrée principal""" return { "message": "API Notariat Pipeline", "version": "1.1.0", "status": "running" }