- Implemented service classes for PedimentoConfigParameters, PedimentoConfigSurcharges, PedimentoConfigUpdateRectification, PedimentoConfigUpdates, PedimentoCustomsOffices, PedimentoDates, PedimentoDecrementables, PedimentoIncrementables, PedimentoIndexes, PedimentoPayments, PedimentoRectificationDestination, PedimentoRectificationOrigin, PedimentoTransportMeans, and PedimentoValidation. - Each service class includes methods for CRUD operations: create, read, update, and delete. - Added a main router for the API v1, integrating various modules including authentication, tenants, licenses, and pedimentos. - Created models for PedimentoValidation with appropriate constraints and relationships.
93 lines
3.1 KiB
Python
93 lines
3.1 KiB
Python
"""
|
|
Routes for PedimentoValidation CRUD operations
|
|
"""
|
|
from fastapi import APIRouter, Depends, HTTPException
|
|
from sqlalchemy.orm import Session
|
|
from core.database import get_core_db
|
|
from core.security import get_current_user, get_tenant_from_token
|
|
|
|
from ..services.pedimento_validation import PedimentoValidationService
|
|
from ..dtos.pedimento_validation import (
|
|
PedimentoValidationCreate,
|
|
PedimentoValidationUpdate,
|
|
PedimentoValidationResponse
|
|
)
|
|
|
|
|
|
router = APIRouter(prefix="/{pedimento_id}/validation")
|
|
|
|
|
|
@router.get("/", response_model=PedimentoValidationResponse)
|
|
async def get_validation(
|
|
pedimento_id: int,
|
|
db: Session = Depends(get_core_db),
|
|
current_user: dict = Depends(get_current_user)
|
|
):
|
|
"""Get validation by pedimento ID"""
|
|
tenant_id = get_tenant_from_token(current_user)
|
|
if not tenant_id:
|
|
raise HTTPException(status_code=400, detail="Tenant ID not found in token")
|
|
|
|
validation = PedimentoValidationService.get_by_pedimento_id(db, pedimento_id, tenant_id)
|
|
if not validation:
|
|
raise HTTPException(status_code=404, detail="Pedimento validation not found")
|
|
|
|
return validation
|
|
|
|
|
|
@router.post("/", response_model=PedimentoValidationResponse, status_code=201)
|
|
async def create_validation(
|
|
pedimento_id: int,
|
|
data: PedimentoValidationCreate,
|
|
db: Session = Depends(get_core_db),
|
|
current_user: dict = Depends(get_current_user)
|
|
):
|
|
"""Create pedimento validation"""
|
|
tenant_id = get_tenant_from_token(current_user)
|
|
if not tenant_id:
|
|
raise HTTPException(status_code=400, detail="Tenant ID not found in token")
|
|
|
|
# Ensure pedimento_id matches
|
|
if data.pedimento_id != pedimento_id:
|
|
raise HTTPException(status_code=400, detail="Pedimento ID mismatch")
|
|
|
|
validation = PedimentoValidationService.create(db, data, tenant_id)
|
|
return validation
|
|
|
|
|
|
@router.put("/", response_model=PedimentoValidationResponse)
|
|
async def update_validation(
|
|
pedimento_id: int,
|
|
data: PedimentoValidationUpdate,
|
|
db: Session = Depends(get_core_db),
|
|
current_user: dict = Depends(get_current_user)
|
|
):
|
|
"""Update pedimento validation"""
|
|
tenant_id = get_tenant_from_token(current_user)
|
|
if not tenant_id:
|
|
raise HTTPException(status_code=400, detail="Tenant ID not found in token")
|
|
|
|
validation = PedimentoValidationService.update(db, pedimento_id, tenant_id, data)
|
|
if not validation:
|
|
raise HTTPException(status_code=404, detail="Pedimento validation not found")
|
|
|
|
return validation
|
|
|
|
|
|
@router.delete("/", status_code=204)
|
|
async def delete_validation(
|
|
pedimento_id: int,
|
|
db: Session = Depends(get_core_db),
|
|
current_user: dict = Depends(get_current_user)
|
|
):
|
|
"""Delete pedimento validation"""
|
|
tenant_id = get_tenant_from_token(current_user)
|
|
if not tenant_id:
|
|
raise HTTPException(status_code=400, detail="Tenant ID not found in token")
|
|
|
|
success = PedimentoValidationService.delete(db, pedimento_id, tenant_id)
|
|
if not success:
|
|
raise HTTPException(status_code=404, detail="Pedimento validation not found")
|
|
|
|
return None
|