- Implemented PaymentsTabForm component for managing payment information. - Implemented TransportTabForm component for managing transport details. - Implemented ValidationTabForm component for managing validation documents. - Enhanced the main edit page to include new tabs and handle data saving for each section. - Added alert components for success and error messages during save operations. - Updated server-side logic to handle fetching and saving of pedimento data.
81 lines
2.2 KiB
Python
81 lines
2.2 KiB
Python
"""
|
|
Anexo76 - Aplicación SaaS para gestión de comercio exterior
|
|
Backend API con FastAPI + Keycloak + SQLAlchemy
|
|
"""
|
|
from fastapi import FastAPI
|
|
from fastapi.middleware.cors import CORSMiddleware
|
|
import logging
|
|
|
|
from core.config import settings
|
|
from core.middleware import (
|
|
TenantMiddleware,
|
|
LicenseValidationMiddleware,
|
|
RequestLoggingMiddleware
|
|
)
|
|
from core.database import init_db
|
|
from api.v1.router import router as api_v1_router
|
|
|
|
# Configurar logging
|
|
logging.basicConfig(
|
|
level=logging.INFO if not settings.DEBUG else logging.DEBUG,
|
|
format='%(asctime)s - %(name)s - %(levelname)s - %(message)s'
|
|
)
|
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
# Crear aplicación FastAPI
|
|
app = FastAPI(
|
|
title="Anexo76 API",
|
|
version=settings.APP_VERSION,
|
|
description="Aplicación SaaS para gestión de comercio exterior conforme a Anexos 24, 30 y 22 del SAT",
|
|
docs_url="/api/docs" if settings.DEBUG else None,
|
|
redoc_url="/api/redoc" if settings.DEBUG else None,
|
|
openapi_url="/api/openapi.json" if settings.DEBUG else None,
|
|
)
|
|
|
|
# Inicializar la base de datos
|
|
@app.on_event("startup")
|
|
async def on_startup():
|
|
"""Evento de inicio de la aplicación"""
|
|
logger.info("Iniciando la aplicación Anexo76...")
|
|
init_db()
|
|
logger.info("Base de datos inicializada correctamente.")
|
|
|
|
# Configurar CORS
|
|
app.add_middleware(
|
|
CORSMiddleware,
|
|
allow_origins=settings.cors_origins_list,
|
|
allow_credentials=True,
|
|
allow_methods=["*"],
|
|
allow_headers=["*"],
|
|
)
|
|
|
|
logger.info(f"CORS configurado para orígenes: {settings.cors_origins_list}")
|
|
|
|
# Agregar middlewares personalizados
|
|
app.add_middleware(RequestLoggingMiddleware)
|
|
app.add_middleware(LicenseValidationMiddleware)
|
|
app.add_middleware(TenantMiddleware)
|
|
|
|
# Registrar routers
|
|
app.include_router(api_v1_router, prefix="/api/v1")
|
|
|
|
@app.get("/api/")
|
|
async def root():
|
|
"""Root endpoint"""
|
|
return {
|
|
"name": "Anexo76 API",
|
|
"version": settings.APP_VERSION,
|
|
"status": "running",
|
|
"docs": "/api/docs" if settings.DEBUG else "disabled in production"
|
|
}
|
|
|
|
|
|
@app.get("/api/health")
|
|
async def health_check():
|
|
"""Health check endpoint"""
|
|
return {
|
|
"status": "healthy",
|
|
"environment": settings.ENVIRONMENT
|
|
}
|