- Added schemas, services, and routers for PROSEC, RCG2, Regulaciones, REIT, RequisitoPrevio, TLCS, and Vehiculos modules. - Each module includes search and get by ID functionalities. - Integrated FastAPI routers for each module into the main SITAR router. - Ensured proper response models using Pydantic for data validation.
42 lines
1.4 KiB
Python
42 lines
1.4 KiB
Python
"""Fracciones USA Router"""
|
|
|
|
from typing import Optional, List
|
|
from fastapi import APIRouter, HTTPException, Query, Depends
|
|
from core.security import get_current_user
|
|
from .service import FraccionesUSAService
|
|
from .schemas import FraccionesUSAResponse
|
|
|
|
router = APIRouter()
|
|
|
|
|
|
@router.get("/", response_model=List[FraccionesUSAResponse])
|
|
async def search_fracciones_usa(
|
|
fraccion: Optional[str] = Query(None, description="Fracción arancelaria USA"),
|
|
skip: int = Query(0, ge=0, description="Registros a saltar"),
|
|
limit: int = Query(100, ge=1, le=1000, description="Máximo de registros"),
|
|
current_user: dict = Depends(get_current_user),
|
|
):
|
|
"""Search USA tariff fractions"""
|
|
try:
|
|
service = FraccionesUSAService.get_instance()
|
|
return await service.search(fraccion=fraccion, skip=skip, limit=limit)
|
|
except Exception as e:
|
|
raise HTTPException(
|
|
status_code=500, detail=f"Error fetching USA Fracciones data: {str(e)}"
|
|
)
|
|
|
|
|
|
@router.get("/{consecutivo}", response_model=FraccionesUSAResponse)
|
|
async def get_fraccion_usa_by_id(
|
|
consecutivo: int,
|
|
current_user: dict = Depends(get_current_user),
|
|
):
|
|
"""Get single USA Fraccion record by CONSECUTIVO"""
|
|
try:
|
|
service = FraccionesUSAService.get_instance()
|
|
return await service.get_by_id(consecutivo)
|
|
except Exception as e:
|
|
raise HTTPException(
|
|
status_code=404, detail=f"USA Fraccion record not found: {str(e)}"
|
|
)
|