Refactor pedimento routes to use company_id instead of tenant_id

- Updated all route files to replace tenant_id with company_id.
- Introduced validate_company_access function to check user access to the specified company.
- Modified service methods to accept company_id as a parameter.
- Adjusted query parameters in route definitions to include company_id.
- Ensured all CRUD operations in pedimento routes validate access based on company_id.
- Added a script to automate the update process for route files.
This commit is contained in:
2025-11-08 10:21:17 -06:00
parent ace261fc57
commit 9b01632fde
20 changed files with 335 additions and 420 deletions

View File

@@ -1,10 +1,10 @@
"""
Routes for PedimentoConfigAdditional CRUD operations
"""
from fastapi import APIRouter, Depends, HTTPException
from fastapi import APIRouter, Depends, HTTPException, Query
from sqlalchemy.orm import Session
from core.database import get_core_db
from core.security import get_current_user, get_tenant_from_token
from core.security import validate_access_to_resource
from ..services.pedimento_config_additional import PedimentoConfigAdditionalService
from ..dtos.pedimento_config_additional import (
@@ -20,15 +20,13 @@ router = APIRouter(prefix="/{pedimento_id}/config-additional")
@router.get("/", response_model=PedimentoConfigAdditionalResponse)
async def get_config_additional(
pedimento_id: int,
company_id: int = Query(..., description="Company ID"),
db: Session = Depends(get_core_db),
current_user: dict = Depends(get_current_user)
):
"""Get config additional 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")
tenant_id = validate_access_to_resource(company_id)
config = PedimentoConfigAdditionalService.get_by_pedimento_id(db, pedimento_id, tenant_id)
config = PedimentoConfigAdditionalService.get_by_pedimento_id(db, pedimento_id, tenant_id, company_id)
if not config:
raise HTTPException(status_code=404, detail="Config additional not found")
@@ -39,21 +37,17 @@ async def get_config_additional(
async def create_config_additional(
pedimento_id: int,
data: PedimentoConfigAdditionalCreate,
company_id: int = Query(..., description="Company ID"),
db: Session = Depends(get_core_db),
current_user: dict = Depends(get_current_user)
):
"""Create config additional"""
tenant_id = get_tenant_from_token(current_user)
if not tenant_id:
raise HTTPException(status_code=400, detail="Tenant ID not found in token")
tenant_id = validate_access_to_resource(company_id)
# Ensure pedimento_id and tenant_id match
# Ensure pedimento_id and company_id match
if data.pedimento_id != pedimento_id:
raise HTTPException(status_code=400, detail="Pedimento ID mismatch")
if data.tenant_id != tenant_id:
raise HTTPException(status_code=403, detail="Tenant ID mismatch")
config = PedimentoConfigAdditionalService.create(db, data)
config = PedimentoConfigAdditionalService.create(db, data, tenant_id, company_id)
return config
@@ -61,15 +55,13 @@ async def create_config_additional(
async def update_config_additional(
pedimento_id: int,
data: PedimentoConfigAdditionalUpdate,
company_id: int = Query(..., description="Company ID"),
db: Session = Depends(get_core_db),
current_user: dict = Depends(get_current_user)
):
"""Update config additional"""
tenant_id = get_tenant_from_token(current_user)
if not tenant_id:
raise HTTPException(status_code=400, detail="Tenant ID not found in token")
tenant_id = validate_access_to_resource(company_id)
config = PedimentoConfigAdditionalService.update(db, pedimento_id, tenant_id, data)
config = PedimentoConfigAdditionalService.update(db, pedimento_id, tenant_id, company_id, data)
if not config:
raise HTTPException(status_code=404, detail="Config additional not found")
@@ -79,15 +71,13 @@ async def update_config_additional(
@router.delete("/", status_code=204)
async def delete_config_additional(
pedimento_id: int,
company_id: int = Query(..., description="Company ID"),
db: Session = Depends(get_core_db),
current_user: dict = Depends(get_current_user)
):
"""Delete config additional"""
tenant_id = get_tenant_from_token(current_user)
if not tenant_id:
raise HTTPException(status_code=400, detail="Tenant ID not found in token")
tenant_id = validate_access_to_resource(company_id)
success = PedimentoConfigAdditionalService.delete(db, pedimento_id, tenant_id)
success = PedimentoConfigAdditionalService.delete(db, pedimento_id, tenant_id, company_id)
if not success:
raise HTTPException(status_code=404, detail="Config additional not found")

View File

@@ -1,10 +1,10 @@
"""
Routes for PedimentoConfigCalculations CRUD operations
"""
from fastapi import APIRouter, Depends, HTTPException
from fastapi import APIRouter, Depends, HTTPException, Query
from sqlalchemy.orm import Session
from core.database import get_core_db
from core.security import get_current_user, get_tenant_from_token
from core.security import validate_access_to_resource
from ..services.pedimento_config_calculations import PedimentoConfigCalculationsService
from ..dtos.pedimento_config_calculations import (
@@ -20,15 +20,13 @@ router = APIRouter(prefix="/{pedimento_id}/config-calculations")
@router.get("/", response_model=PedimentoConfigCalculationsResponse)
async def get_config_calculations(
pedimento_id: int,
company_id: int = Query(..., description="Company ID"),
db: Session = Depends(get_core_db),
current_user: dict = Depends(get_current_user)
):
"""Get config calculations 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")
tenant_id = validate_access_to_resource(company_id)
config = PedimentoConfigCalculationsService.get_by_pedimento_id(db, pedimento_id, tenant_id)
config = PedimentoConfigCalculationsService.get_by_pedimento_id(db, pedimento_id, tenant_id, company_id)
if not config:
raise HTTPException(status_code=404, detail="Config calculations not found")
@@ -39,19 +37,17 @@ async def get_config_calculations(
async def create_config_calculations(
pedimento_id: int,
data: PedimentoConfigCalculationsCreate,
company_id: int = Query(..., description="Company ID"),
db: Session = Depends(get_core_db),
current_user: dict = Depends(get_current_user)
):
"""Create config calculations"""
tenant_id = get_tenant_from_token(current_user)
if not tenant_id:
raise HTTPException(status_code=400, detail="Tenant ID not found in token")
tenant_id = validate_access_to_resource(company_id)
# Ensure pedimento_id matches
if data.pedimento_id != pedimento_id:
raise HTTPException(status_code=400, detail="Pedimento ID mismatch")
config = PedimentoConfigCalculationsService.create(db, data, tenant_id)
config = PedimentoConfigCalculationsService.create(db, data, tenant_id, company_id)
return config
@@ -59,15 +55,13 @@ async def create_config_calculations(
async def update_config_calculations(
pedimento_id: int,
data: PedimentoConfigCalculationsUpdate,
company_id: int = Query(..., description="Company ID"),
db: Session = Depends(get_core_db),
current_user: dict = Depends(get_current_user)
):
"""Update config calculations"""
tenant_id = get_tenant_from_token(current_user)
if not tenant_id:
raise HTTPException(status_code=400, detail="Tenant ID not found in token")
tenant_id = validate_access_to_resource(company_id)
config = PedimentoConfigCalculationsService.update(db, pedimento_id, tenant_id, data)
config = PedimentoConfigCalculationsService.update(db, pedimento_id, tenant_id, company_id, data)
if not config:
raise HTTPException(status_code=404, detail="Config calculations not found")
@@ -77,15 +71,13 @@ async def update_config_calculations(
@router.delete("/", status_code=204)
async def delete_config_calculations(
pedimento_id: int,
company_id: int = Query(..., description="Company ID"),
db: Session = Depends(get_core_db),
current_user: dict = Depends(get_current_user)
):
"""Delete config calculations"""
tenant_id = get_tenant_from_token(current_user)
if not tenant_id:
raise HTTPException(status_code=400, detail="Tenant ID not found in token")
tenant_id = validate_access_to_resource(company_id)
success = PedimentoConfigCalculationsService.delete(db, pedimento_id, tenant_id)
success = PedimentoConfigCalculationsService.delete(db, pedimento_id, company_id)
if not success:
raise HTTPException(status_code=404, detail="Config calculations not found")

View File

@@ -1,10 +1,10 @@
"""
Routes for PedimentoConfigParameters CRUD operations
"""
from fastapi import APIRouter, Depends, HTTPException
from fastapi import APIRouter, Depends, HTTPException, Query
from sqlalchemy.orm import Session
from core.database import get_core_db
from core.security import get_current_user, get_tenant_from_token
from core.security import validate_access_to_resource
from ..services.pedimento_config_parameters import PedimentoConfigParametersService
from ..dtos.pedimento_config_parameters import (
@@ -20,15 +20,13 @@ router = APIRouter(prefix="/{pedimento_id}/config-parameters")
@router.get("/", response_model=PedimentoConfigParametersResponse)
async def get_config_parameters(
pedimento_id: int,
company_id: int = Query(..., description="Company ID"),
db: Session = Depends(get_core_db),
current_user: dict = Depends(get_current_user)
):
"""Get config parameters 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")
tenant_id = validate_access_to_resource(company_id)
config = PedimentoConfigParametersService.get_by_pedimento_id(db, pedimento_id, tenant_id)
config = PedimentoConfigParametersService.get_by_pedimento_id(db, pedimento_id, tenant_id, company_id)
if not config:
raise HTTPException(status_code=404, detail="Config parameters not found")
@@ -39,19 +37,17 @@ async def get_config_parameters(
async def create_config_parameters(
pedimento_id: int,
data: PedimentoConfigParametersCreate,
company_id: int = Query(..., description="Company ID"),
db: Session = Depends(get_core_db),
current_user: dict = Depends(get_current_user)
):
"""Create config parameters"""
tenant_id = get_tenant_from_token(current_user)
if not tenant_id:
raise HTTPException(status_code=400, detail="Tenant ID not found in token")
tenant_id = validate_access_to_resource(company_id)
# Ensure pedimento_id matches
if data.pedimento_id != pedimento_id:
raise HTTPException(status_code=400, detail="Pedimento ID mismatch")
config = PedimentoConfigParametersService.create(db, data, tenant_id)
config = PedimentoConfigParametersService.create(db, data, tenant_id, company_id)
return config
@@ -59,15 +55,13 @@ async def create_config_parameters(
async def update_config_parameters(
pedimento_id: int,
data: PedimentoConfigParametersUpdate,
company_id: int = Query(..., description="Company ID"),
db: Session = Depends(get_core_db),
current_user: dict = Depends(get_current_user)
):
"""Update config parameters"""
tenant_id = get_tenant_from_token(current_user)
if not tenant_id:
raise HTTPException(status_code=400, detail="Tenant ID not found in token")
tenant_id = validate_access_to_resource(company_id)
config = PedimentoConfigParametersService.update(db, pedimento_id, tenant_id, data)
config = PedimentoConfigParametersService.update(db, pedimento_id, tenant_id, company_id, data)
if not config:
raise HTTPException(status_code=404, detail="Config parameters not found")
@@ -77,15 +71,13 @@ async def update_config_parameters(
@router.delete("/", status_code=204)
async def delete_config_parameters(
pedimento_id: int,
company_id: int = Query(..., description="Company ID"),
db: Session = Depends(get_core_db),
current_user: dict = Depends(get_current_user)
):
"""Delete config parameters"""
tenant_id = get_tenant_from_token(current_user)
if not tenant_id:
raise HTTPException(status_code=400, detail="Tenant ID not found in token")
tenant_id = validate_access_to_resource(company_id)
success = PedimentoConfigParametersService.delete(db, pedimento_id, tenant_id)
success = PedimentoConfigParametersService.delete(db, pedimento_id, tenant_id, company_id)
if not success:
raise HTTPException(status_code=404, detail="Config parameters not found")

View File

@@ -1,10 +1,10 @@
"""
Routes for PedimentoConfigSurcharges CRUD operations
"""
from fastapi import APIRouter, Depends, HTTPException
from fastapi import APIRouter, Depends, HTTPException, Query
from sqlalchemy.orm import Session
from core.database import get_core_db
from core.security import get_current_user, get_tenant_from_token
from core.security import validate_access_to_resource
from ..services.pedimento_config_surcharges import PedimentoConfigSurchargesService
from ..dtos.pedimento_config_surcharges import (
@@ -20,15 +20,13 @@ router = APIRouter(prefix="/{pedimento_id}/config-surcharges")
@router.get("/", response_model=PedimentoConfigSurchargesResponse)
async def get_config_surcharges(
pedimento_id: int,
company_id: int = Query(..., description="Company ID"),
db: Session = Depends(get_core_db),
current_user: dict = Depends(get_current_user)
):
"""Get config surcharges 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")
tenant_id = validate_access_to_resource(company_id)
config = PedimentoConfigSurchargesService.get_by_pedimento_id(db, pedimento_id, tenant_id)
config = PedimentoConfigSurchargesService.get_by_pedimento_id(db, pedimento_id, tenant_id, company_id)
if not config:
raise HTTPException(status_code=404, detail="Config surcharges not found")
@@ -39,19 +37,17 @@ async def get_config_surcharges(
async def create_config_surcharges(
pedimento_id: int,
data: PedimentoConfigSurchargesCreate,
company_id: int = Query(..., description="Company ID"),
db: Session = Depends(get_core_db),
current_user: dict = Depends(get_current_user)
):
"""Create config surcharges"""
tenant_id = get_tenant_from_token(current_user)
if not tenant_id:
raise HTTPException(status_code=400, detail="Tenant ID not found in token")
tenant_id = validate_access_to_resource(company_id)
# Ensure pedimento_id matches
if data.pedimento_id != pedimento_id:
raise HTTPException(status_code=400, detail="Pedimento ID mismatch")
config = PedimentoConfigSurchargesService.create(db, data, tenant_id)
config = PedimentoConfigSurchargesService.create(db, data, tenant_id, company_id)
return config
@@ -59,15 +55,13 @@ async def create_config_surcharges(
async def update_config_surcharges(
pedimento_id: int,
data: PedimentoConfigSurchargesUpdate,
company_id: int = Query(..., description="Company ID"),
db: Session = Depends(get_core_db),
current_user: dict = Depends(get_current_user)
):
"""Update config surcharges"""
tenant_id = get_tenant_from_token(current_user)
if not tenant_id:
raise HTTPException(status_code=400, detail="Tenant ID not found in token")
tenant_id = validate_access_to_resource(company_id)
config = PedimentoConfigSurchargesService.update(db, pedimento_id, tenant_id, data)
config = PedimentoConfigSurchargesService.update(db, pedimento_id, tenant_id, company_id, data)
if not config:
raise HTTPException(status_code=404, detail="Config surcharges not found")
@@ -77,15 +71,13 @@ async def update_config_surcharges(
@router.delete("/", status_code=204)
async def delete_config_surcharges(
pedimento_id: int,
company_id: int = Query(..., description="Company ID"),
db: Session = Depends(get_core_db),
current_user: dict = Depends(get_current_user)
):
"""Delete config surcharges"""
tenant_id = get_tenant_from_token(current_user)
if not tenant_id:
raise HTTPException(status_code=400, detail="Tenant ID not found in token")
tenant_id = validate_access_to_resource(company_id)
success = PedimentoConfigSurchargesService.delete(db, pedimento_id, tenant_id)
success = PedimentoConfigSurchargesService.delete(db, pedimento_id, tenant_id, company_id)
if not success:
raise HTTPException(status_code=404, detail="Config surcharges not found")

View File

@@ -1,10 +1,10 @@
"""
Routes for PedimentoConfigUpdateRectification CRUD operations
"""
from fastapi import APIRouter, Depends, HTTPException
from fastapi import APIRouter, Depends, HTTPException, Query
from sqlalchemy.orm import Session
from core.database import get_core_db
from core.security import get_current_user, get_tenant_from_token
from core.security import validate_access_to_resource
from ..services.pedimento_config_update_rectification import PedimentoConfigUpdateRectificationService
from ..dtos.pedimento_config_update_rectification import (
@@ -20,15 +20,13 @@ router = APIRouter(prefix="/{pedimento_id}/config-update-rectification")
@router.get("/", response_model=PedimentoConfigUpdateRectificationResponse)
async def get_config_update_rectification(
pedimento_id: int,
company_id: int = Query(..., description="Company ID"),
db: Session = Depends(get_core_db),
current_user: dict = Depends(get_current_user)
):
"""Get config update rectification 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")
tenant_id = validate_access_to_resource(company_id)
config = PedimentoConfigUpdateRectificationService.get_by_pedimento_id(db, pedimento_id, tenant_id)
config = PedimentoConfigUpdateRectificationService.get_by_pedimento_id(db, pedimento_id, tenant_id, company_id)
if not config:
raise HTTPException(status_code=404, detail="Config update rectification not found")
@@ -39,19 +37,17 @@ async def get_config_update_rectification(
async def create_config_update_rectification(
pedimento_id: int,
data: PedimentoConfigUpdateRectificationCreate,
company_id: int = Query(..., description="Company ID"),
db: Session = Depends(get_core_db),
current_user: dict = Depends(get_current_user)
):
"""Create config update rectification"""
tenant_id = get_tenant_from_token(current_user)
if not tenant_id:
raise HTTPException(status_code=400, detail="Tenant ID not found in token")
tenant_id = validate_access_to_resource(company_id)
# Ensure pedimento_id matches
if data.pedimento_id != pedimento_id:
raise HTTPException(status_code=400, detail="Pedimento ID mismatch")
config = PedimentoConfigUpdateRectificationService.create(db, data, tenant_id)
config = PedimentoConfigUpdateRectificationService.create(db, data, tenant_id, company_id)
return config
@@ -59,15 +55,13 @@ async def create_config_update_rectification(
async def update_config_update_rectification(
pedimento_id: int,
data: PedimentoConfigUpdateRectificationUpdate,
company_id: int = Query(..., description="Company ID"),
db: Session = Depends(get_core_db),
current_user: dict = Depends(get_current_user)
):
"""Update config update rectification"""
tenant_id = get_tenant_from_token(current_user)
if not tenant_id:
raise HTTPException(status_code=400, detail="Tenant ID not found in token")
tenant_id = validate_access_to_resource(company_id)
config = PedimentoConfigUpdateRectificationService.update(db, pedimento_id, tenant_id, data)
config = PedimentoConfigUpdateRectificationService.update(db, pedimento_id, tenant_id, company_id, data)
if not config:
raise HTTPException(status_code=404, detail="Config update rectification not found")
@@ -77,15 +71,13 @@ async def update_config_update_rectification(
@router.delete("/", status_code=204)
async def delete_config_update_rectification(
pedimento_id: int,
company_id: int = Query(..., description="Company ID"),
db: Session = Depends(get_core_db),
current_user: dict = Depends(get_current_user)
):
"""Delete config update rectification"""
tenant_id = get_tenant_from_token(current_user)
if not tenant_id:
raise HTTPException(status_code=400, detail="Tenant ID not found in token")
tenant_id = validate_access_to_resource(company_id)
success = PedimentoConfigUpdateRectificationService.delete(db, pedimento_id, tenant_id)
success = PedimentoConfigUpdateRectificationService.delete(db, pedimento_id, tenant_id, company_id)
if not success:
raise HTTPException(status_code=404, detail="Config update rectification not found")

View File

@@ -1,10 +1,10 @@
"""
Routes for PedimentoConfigUpdates CRUD operations
"""
from fastapi import APIRouter, Depends, HTTPException
from fastapi import APIRouter, Depends, HTTPException, Query
from sqlalchemy.orm import Session
from core.database import get_core_db
from core.security import get_current_user, get_tenant_from_token
from core.security import validate_access_to_resource
from ..services.pedimento_config_updates import PedimentoConfigUpdatesService
from ..dtos.pedimento_config_updates import (
@@ -20,15 +20,13 @@ router = APIRouter(prefix="/{pedimento_id}/config-updates")
@router.get("/", response_model=PedimentoConfigUpdatesResponse)
async def get_config_updates(
pedimento_id: int,
company_id: int = Query(..., description="Company ID"),
db: Session = Depends(get_core_db),
current_user: dict = Depends(get_current_user)
):
"""Get config updates 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")
tenant_id = validate_access_to_resource(company_id)
config = PedimentoConfigUpdatesService.get_by_pedimento_id(db, pedimento_id, tenant_id)
config = PedimentoConfigUpdatesService.get_by_pedimento_id(db, pedimento_id, tenant_id, company_id)
if not config:
raise HTTPException(status_code=404, detail="Config updates not found")
@@ -39,19 +37,17 @@ async def get_config_updates(
async def create_config_updates(
pedimento_id: int,
data: PedimentoConfigUpdatesCreate,
db: Session = Depends(get_core_db),
current_user: dict = Depends(get_current_user)
company_id: int = Query(..., description="Company ID"),
db: Session = Depends(get_core_db)
):
"""Create config updates"""
tenant_id = get_tenant_from_token(current_user)
if not tenant_id:
raise HTTPException(status_code=400, detail="Tenant ID not found in token")
tenant_id = validate_access_to_resource(company_id)
# Ensure pedimento_id matches
if data.pedimento_id != pedimento_id:
raise HTTPException(status_code=400, detail="Pedimento ID mismatch")
config = PedimentoConfigUpdatesService.create(db, data, tenant_id)
config = PedimentoConfigUpdatesService.create(db, data, tenant_id, company_id)
return config
@@ -59,15 +55,13 @@ async def create_config_updates(
async def update_config_updates(
pedimento_id: int,
data: PedimentoConfigUpdatesUpdate,
company_id: int = Query(..., description="Company ID"),
db: Session = Depends(get_core_db),
current_user: dict = Depends(get_current_user)
):
"""Update config updates"""
tenant_id = get_tenant_from_token(current_user)
if not tenant_id:
raise HTTPException(status_code=400, detail="Tenant ID not found in token")
tenant_id = validate_access_to_resource(company_id)
config = PedimentoConfigUpdatesService.update(db, pedimento_id, tenant_id, data)
config = PedimentoConfigUpdatesService.update(db, pedimento_id, tenant_id, company_id, data)
if not config:
raise HTTPException(status_code=404, detail="Config updates not found")
@@ -77,15 +71,13 @@ async def update_config_updates(
@router.delete("/", status_code=204)
async def delete_config_updates(
pedimento_id: int,
company_id: int = Query(..., description="Company ID"),
db: Session = Depends(get_core_db),
current_user: dict = Depends(get_current_user)
):
"""Delete config updates"""
tenant_id = get_tenant_from_token(current_user)
if not tenant_id:
raise HTTPException(status_code=400, detail="Tenant ID not found in token")
tenant_id = validate_access_to_resource(company_id)
success = PedimentoConfigUpdatesService.delete(db, pedimento_id, tenant_id)
success = PedimentoConfigUpdatesService.delete(db, pedimento_id, tenant_id, company_id)
if not success:
raise HTTPException(status_code=404, detail="Config updates not found")

View File

@@ -1,12 +1,11 @@
"""
Routes for PedimentoCustomsOffices CRUD operations
"""
from fastapi import APIRouter, Depends, HTTPException
from fastapi import APIRouter, Depends, HTTPException, Query
from sqlalchemy.orm import Session
from typing import List
from core.database import get_core_db
from core.security import get_current_user, get_tenant_from_token
from core.security import validate_access_to_resource
from ..services.pedimento_customs_offices import PedimentoCustomsOfficesService
from ..dtos.pedimento_customs_offices import (
PedimentoCustomsOfficesCreate,
@@ -21,15 +20,13 @@ router = APIRouter(prefix="/{pedimento_id}/customs-offices")
@router.get("/", response_model=List[PedimentoCustomsOfficesResponse])
async def list_customs_offices(
pedimento_id: int,
company_id: int = Query(..., description="Company ID"),
db: Session = Depends(get_core_db),
current_user: dict = Depends(get_current_user)
):
"""Get all customs offices for a pedimento"""
tenant_id = get_tenant_from_token(current_user)
if not tenant_id:
raise HTTPException(status_code=400, detail="Tenant ID not found in token")
tenant_id = validate_access_to_resource(company_id)
offices = PedimentoCustomsOfficesService.get_by_pedimento_id(db, pedimento_id, tenant_id)
offices = PedimentoCustomsOfficesService.get_by_pedimento_id(db, pedimento_id, tenant_id, company_id)
return offices
@@ -37,15 +34,13 @@ async def list_customs_offices(
async def get_customs_office(
pedimento_id: int,
office_id: int,
company_id: int = Query(..., description="Company ID"),
db: Session = Depends(get_core_db),
current_user: dict = Depends(get_current_user)
):
"""Get a specific customs office by 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")
tenant_id = validate_access_to_resource(company_id)
office = PedimentoCustomsOfficesService.get_by_id(db, office_id, pedimento_id, tenant_id)
office = PedimentoCustomsOfficesService.get_by_id(db, office_id, pedimento_id, tenant_id, company_id)
if not office:
raise HTTPException(status_code=404, detail="Customs office not found")
@@ -56,19 +51,17 @@ async def get_customs_office(
async def create_customs_office(
pedimento_id: int,
data: PedimentoCustomsOfficesCreate,
company_id: int = Query(..., description="Company ID"),
db: Session = Depends(get_core_db),
current_user: dict = Depends(get_current_user)
):
"""Create a new customs office"""
tenant_id = get_tenant_from_token(current_user)
if not tenant_id:
raise HTTPException(status_code=400, detail="Tenant ID not found in token")
tenant_id = validate_access_to_resource(company_id)
# Ensure pedimento_id matches
if data.pedimento_id != pedimento_id:
raise HTTPException(status_code=400, detail="Pedimento ID mismatch")
office = PedimentoCustomsOfficesService.create(db, data, tenant_id)
office = PedimentoCustomsOfficesService.create(db, data, tenant_id, company_id)
return office
@@ -77,15 +70,13 @@ async def update_customs_office(
pedimento_id: int,
office_id: int,
data: PedimentoCustomsOfficesUpdate,
company_id: int = Query(..., description="Company ID"),
db: Session = Depends(get_core_db),
current_user: dict = Depends(get_current_user)
):
"""Update a customs office"""
tenant_id = get_tenant_from_token(current_user)
if not tenant_id:
raise HTTPException(status_code=400, detail="Tenant ID not found in token")
tenant_id = validate_access_to_resource(company_id)
office = PedimentoCustomsOfficesService.update(db, office_id, pedimento_id, tenant_id, data)
office = PedimentoCustomsOfficesService.update(db, office_id, pedimento_id, tenant_id, company_id, data)
if not office:
raise HTTPException(status_code=404, detail="Customs office not found")
@@ -96,15 +87,13 @@ async def update_customs_office(
async def delete_customs_office(
pedimento_id: int,
office_id: int,
company_id: int = Query(..., description="Company ID"),
db: Session = Depends(get_core_db),
current_user: dict = Depends(get_current_user)
):
"""Delete a customs office"""
tenant_id = get_tenant_from_token(current_user)
if not tenant_id:
raise HTTPException(status_code=400, detail="Tenant ID not found in token")
tenant_id = validate_access_to_resource(company_id)
success = PedimentoCustomsOfficesService.delete(db, office_id, pedimento_id, tenant_id)
success = PedimentoCustomsOfficesService.delete(db, office_id, pedimento_id, tenant_id, company_id)
if not success:
raise HTTPException(status_code=404, detail="Customs office not found")

View File

@@ -2,10 +2,10 @@
Routes for PedimentoDates CRUD operations
"""
import logging
from fastapi import APIRouter, Depends, HTTPException
from fastapi import APIRouter, Depends, HTTPException, Query
from sqlalchemy.orm import Session
from core.database import get_core_db
from core.security import get_current_user, get_tenant_from_token
from core.security import validate_access_to_resource
from ..services.pedimento_dates import PedimentoDatesService
from ..dtos.pedimento_dates import (
@@ -21,15 +21,13 @@ logger = logging.getLogger(__name__)
@router.get("/", response_model=PedimentoDatesResponse)
async def get_dates(
pedimento_id: int,
company_id: int = Query(..., description="Company ID"),
db: Session = Depends(get_core_db),
current_user: dict = Depends(get_current_user)
):
"""Get dates 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")
tenant_id = validate_access_to_resource(company_id)
dates = PedimentoDatesService.get_by_pedimento_id(db, pedimento_id, tenant_id)
dates = PedimentoDatesService.get_by_pedimento_id(db, pedimento_id, tenant_id, company_id)
if not dates:
raise HTTPException(status_code=404, detail="Pedimento dates not found")
@@ -39,15 +37,13 @@ async def get_dates(
@router.post("/", response_model=PedimentoDatesResponse, status_code=201)
async def create_dates(
data: PedimentoDatesCreate,
company_id: int = Query(..., description="Company ID"),
db: Session = Depends(get_core_db),
current_user: dict = Depends(get_current_user)
):
"""Create pedimento dates"""
tenant_id = get_tenant_from_token(current_user)
if not tenant_id:
raise HTTPException(status_code=400, detail="Tenant ID not found in token")
tenant_id = validate_access_to_resource(company_id)
dates = PedimentoDatesService.create(db, data, tenant_id)
dates = PedimentoDatesService.create(db, data, tenant_id, company_id)
return dates
@@ -55,15 +51,13 @@ async def create_dates(
async def update_dates(
pedimento_id: int,
data: PedimentoDatesUpdate,
company_id: int = Query(..., description="Company ID"),
db: Session = Depends(get_core_db),
current_user: dict = Depends(get_current_user)
):
"""Update pedimento dates"""
tenant_id = get_tenant_from_token(current_user)
if not tenant_id:
raise HTTPException(status_code=400, detail="Tenant ID not found in token")
tenant_id = validate_access_to_resource(company_id)
dates = PedimentoDatesService.update(db, pedimento_id, tenant_id, data)
dates = PedimentoDatesService.update(db, pedimento_id, tenant_id, company_id, data)
if not dates:
raise HTTPException(status_code=404, detail="Pedimento dates not found")
@@ -73,15 +67,13 @@ async def update_dates(
@router.delete("/", status_code=204)
async def delete_dates(
pedimento_id: int,
company_id: int = Query(..., description="Company ID"),
db: Session = Depends(get_core_db),
current_user: dict = Depends(get_current_user)
):
"""Delete pedimento dates"""
tenant_id = get_tenant_from_token(current_user)
if not tenant_id:
raise HTTPException(status_code=400, detail="Tenant ID not found in token")
tenant_id = validate_access_to_resource(company_id)
success = PedimentoDatesService.delete(db, pedimento_id, tenant_id)
success = PedimentoDatesService.delete(db, pedimento_id, tenant_id, company_id)
if not success:
raise HTTPException(status_code=404, detail="Pedimento dates not found")

View File

@@ -1,11 +1,11 @@
"""
Routes for PedimentoDecrementables CRUD operations
"""
from fastapi import APIRouter, Depends, HTTPException
from fastapi import APIRouter, Depends, HTTPException, Query
from sqlalchemy.orm import Session
from typing import List
from core.database import get_core_db
from core.security import get_current_user, get_tenant_from_token
from core.security import validate_access_to_resource
from ..services.pedimento_decrementables import PedimentoDecrementablesService
from ..dtos.pedimento_decrementables import (
@@ -21,15 +21,13 @@ router = APIRouter(prefix="/{pedimento_id}/decrementables")
@router.get("/", response_model=List[PedimentoDecrementablesResponse])
async def list_decrementables(
pedimento_id: int,
company_id: int = Query(..., description="Company ID"),
db: Session = Depends(get_core_db),
current_user: dict = Depends(get_current_user)
):
"""Get all decrementables for a pedimento"""
tenant_id = get_tenant_from_token(current_user)
if not tenant_id:
raise HTTPException(status_code=400, detail="Tenant ID not found in token")
tenant_id = validate_access_to_resource(company_id)
decrementables = PedimentoDecrementablesService.get_by_pedimento_id(db, pedimento_id, tenant_id)
decrementables = PedimentoDecrementablesService.get_by_pedimento_id(db, pedimento_id, tenant_id, company_id)
return decrementables
@@ -37,15 +35,13 @@ async def list_decrementables(
async def get_decrementable(
pedimento_id: int,
decrementable_id: int,
company_id: int = Query(..., description="Company ID"),
db: Session = Depends(get_core_db),
current_user: dict = Depends(get_current_user)
):
"""Get a specific decrementable by 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")
tenant_id = validate_access_to_resource(company_id)
decrementable = PedimentoDecrementablesService.get_by_id(db, decrementable_id, pedimento_id, tenant_id)
decrementable = PedimentoDecrementablesService.get_by_id(db, decrementable_id, pedimento_id, tenant_id, company_id)
if not decrementable:
raise HTTPException(status_code=404, detail="Decrementable not found")
@@ -56,19 +52,17 @@ async def get_decrementable(
async def create_decrementable(
pedimento_id: int,
data: PedimentoDecrementablesCreate,
company_id: int = Query(..., description="Company ID"),
db: Session = Depends(get_core_db),
current_user: dict = Depends(get_current_user)
):
"""Create a new decrementable"""
tenant_id = get_tenant_from_token(current_user)
if not tenant_id:
raise HTTPException(status_code=400, detail="Tenant ID not found in token")
tenant_id = validate_access_to_resource(company_id)
# Ensure pedimento_id matches
if data.pedimento_id != pedimento_id:
raise HTTPException(status_code=400, detail="Pedimento ID mismatch")
decrementable = PedimentoDecrementablesService.create(db, data, tenant_id)
decrementable = PedimentoDecrementablesService.create(db, data, tenant_id, company_id)
return decrementable
@@ -77,15 +71,13 @@ async def update_decrementable(
pedimento_id: int,
decrementable_id: int,
data: PedimentoDecrementablesUpdate,
company_id: int = Query(..., description="Company ID"),
db: Session = Depends(get_core_db),
current_user: dict = Depends(get_current_user)
):
"""Update a decrementable"""
tenant_id = get_tenant_from_token(current_user)
if not tenant_id:
raise HTTPException(status_code=400, detail="Tenant ID not found in token")
tenant_id = validate_access_to_resource(company_id)
decrementable = PedimentoDecrementablesService.update(db, decrementable_id, pedimento_id, tenant_id, data)
decrementable = PedimentoDecrementablesService.update(db, decrementable_id, pedimento_id, tenant_id, company_id, data)
if not decrementable:
raise HTTPException(status_code=404, detail="Decrementable not found")
@@ -96,15 +88,13 @@ async def update_decrementable(
async def delete_decrementable(
pedimento_id: int,
decrementable_id: int,
company_id: int = Query(..., description="Company ID"),
db: Session = Depends(get_core_db),
current_user: dict = Depends(get_current_user)
):
"""Delete a decrementable"""
tenant_id = get_tenant_from_token(current_user)
if not tenant_id:
raise HTTPException(status_code=400, detail="Tenant ID not found in token")
tenant_id = validate_access_to_resource(company_id)
success = PedimentoDecrementablesService.delete(db, decrementable_id, pedimento_id, tenant_id)
success = PedimentoDecrementablesService.delete(db, decrementable_id, pedimento_id, tenant_id, company_id)
if not success:
raise HTTPException(status_code=404, detail="Decrementable not found")

View File

@@ -1,11 +1,11 @@
"""
Routes for PedimentoIncrementables CRUD operations
"""
from fastapi import APIRouter, Depends, HTTPException
from fastapi import APIRouter, Depends, HTTPException, Query
from sqlalchemy.orm import Session
from typing import List
from core.database import get_core_db
from core.security import get_current_user, get_tenant_from_token
from core.security import validate_access_to_resource
from ..services.pedimento_incrementables import PedimentoIncrementablesService
from ..dtos.pedimento_incrementables import (
@@ -21,15 +21,13 @@ router = APIRouter(prefix="/{pedimento_id}/incrementables")
@router.get("/", response_model=List[PedimentoIncrementablesResponse])
async def list_incrementables(
pedimento_id: int,
company_id: int = Query(..., description="Company ID"),
db: Session = Depends(get_core_db),
current_user: dict = Depends(get_current_user)
):
"""Get all incrementables for a pedimento"""
tenant_id = get_tenant_from_token(current_user)
if not tenant_id:
raise HTTPException(status_code=400, detail="Tenant ID not found in token")
tenant_id = validate_access_to_resource(company_id)
incrementables = PedimentoIncrementablesService.get_by_pedimento_id(db, pedimento_id, tenant_id)
incrementables = PedimentoIncrementablesService.get_by_pedimento_id(db, pedimento_id, tenant_id, company_id)
return incrementables
@@ -37,15 +35,13 @@ async def list_incrementables(
async def get_incrementable(
pedimento_id: int,
incrementable_id: int,
company_id: int = Query(..., description="Company ID"),
db: Session = Depends(get_core_db),
current_user: dict = Depends(get_current_user)
):
"""Get a specific incrementable by 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")
tenant_id = validate_access_to_resource(company_id)
incrementable = PedimentoIncrementablesService.get_by_id(db, incrementable_id, pedimento_id, tenant_id)
incrementable = PedimentoIncrementablesService.get_by_id(db, incrementable_id, pedimento_id, tenant_id, company_id)
if not incrementable:
raise HTTPException(status_code=404, detail="Incrementable not found")
@@ -56,19 +52,17 @@ async def get_incrementable(
async def create_incrementable(
pedimento_id: int,
data: PedimentoIncrementablesCreate,
company_id: int = Query(..., description="Company ID"),
db: Session = Depends(get_core_db),
current_user: dict = Depends(get_current_user)
):
"""Create a new incrementable"""
tenant_id = get_tenant_from_token(current_user)
if not tenant_id:
raise HTTPException(status_code=400, detail="Tenant ID not found in token")
tenant_id = validate_access_to_resource(company_id)
# Ensure pedimento_id matches
if data.pedimento_id != pedimento_id:
raise HTTPException(status_code=400, detail="Pedimento ID mismatch")
incrementable = PedimentoIncrementablesService.create(db, data, tenant_id)
incrementable = PedimentoIncrementablesService.create(db, data, tenant_id, company_id)
return incrementable
@@ -77,15 +71,13 @@ async def update_incrementable(
pedimento_id: int,
incrementable_id: int,
data: PedimentoIncrementablesUpdate,
company_id: int = Query(..., description="Company ID"),
db: Session = Depends(get_core_db),
current_user: dict = Depends(get_current_user)
):
"""Update an incrementable"""
tenant_id = get_tenant_from_token(current_user)
if not tenant_id:
raise HTTPException(status_code=400, detail="Tenant ID not found in token")
tenant_id = validate_access_to_resource(company_id)
incrementable = PedimentoIncrementablesService.update(db, incrementable_id, pedimento_id, tenant_id, data)
incrementable = PedimentoIncrementablesService.update(db, incrementable_id, pedimento_id, tenant_id, company_id, data)
if not incrementable:
raise HTTPException(status_code=404, detail="Incrementable not found")
@@ -96,15 +88,13 @@ async def update_incrementable(
async def delete_incrementable(
pedimento_id: int,
incrementable_id: int,
company_id: int = Query(..., description="Company ID"),
db: Session = Depends(get_core_db),
current_user: dict = Depends(get_current_user)
):
"""Delete an incrementable"""
tenant_id = get_tenant_from_token(current_user)
if not tenant_id:
raise HTTPException(status_code=400, detail="Tenant ID not found in token")
tenant_id = validate_access_to_resource(company_id)
success = PedimentoIncrementablesService.delete(db, incrementable_id, pedimento_id, tenant_id)
success = PedimentoIncrementablesService.delete(db, incrementable_id, pedimento_id, tenant_id, company_id)
if not success:
raise HTTPException(status_code=404, detail="Incrementable not found")

View File

@@ -1,10 +1,10 @@
"""
Routes for PedimentoIndexes CRUD operations
"""
from fastapi import APIRouter, Depends, HTTPException
from fastapi import APIRouter, Depends, HTTPException, Query
from sqlalchemy.orm import Session
from core.database import get_core_db
from core.security import get_current_user, get_tenant_from_token
from core.security import validate_access_to_resource
from ..services.pedimento_indexes import PedimentoIndexesService
from ..dtos.pedimento_indexes import (
@@ -20,15 +20,13 @@ router = APIRouter(prefix="/{pedimento_id}/indexes")
@router.get("/", response_model=PedimentoIndexesResponse)
async def get_indexes(
pedimento_id: int,
company_id: int = Query(..., description="Company ID"),
db: Session = Depends(get_core_db),
current_user: dict = Depends(get_current_user)
):
"""Get indexes 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")
tenant_id = validate_access_to_resource(company_id)
indexes = PedimentoIndexesService.get_by_pedimento_id(db, pedimento_id, tenant_id)
indexes = PedimentoIndexesService.get_by_pedimento_id(db, pedimento_id, tenant_id, company_id)
if not indexes:
raise HTTPException(status_code=404, detail="Pedimento indexes not found")
@@ -39,19 +37,17 @@ async def get_indexes(
async def create_indexes(
pedimento_id: int,
data: PedimentoIndexesCreate,
company_id: int = Query(..., description="Company ID"),
db: Session = Depends(get_core_db),
current_user: dict = Depends(get_current_user)
):
"""Create pedimento indexes"""
tenant_id = get_tenant_from_token(current_user)
if not tenant_id:
raise HTTPException(status_code=400, detail="Tenant ID not found in token")
tenant_id = validate_access_to_resource(company_id)
# Ensure pedimento_id matches
if data.pedimento_id != pedimento_id:
raise HTTPException(status_code=400, detail="Pedimento ID mismatch")
indexes = PedimentoIndexesService.create(db, data, tenant_id)
indexes = PedimentoIndexesService.create(db, data, tenant_id, company_id)
return indexes
@@ -59,15 +55,13 @@ async def create_indexes(
async def update_indexes(
pedimento_id: int,
data: PedimentoIndexesUpdate,
company_id: int = Query(..., description="Company ID"),
db: Session = Depends(get_core_db),
current_user: dict = Depends(get_current_user)
):
"""Update pedimento indexes"""
tenant_id = get_tenant_from_token(current_user)
if not tenant_id:
raise HTTPException(status_code=400, detail="Tenant ID not found in token")
tenant_id = validate_access_to_resource(company_id)
indexes = PedimentoIndexesService.update(db, pedimento_id, tenant_id, data)
indexes = PedimentoIndexesService.update(db, pedimento_id, tenant_id, company_id, data)
if not indexes:
raise HTTPException(status_code=404, detail="Pedimento indexes not found")
@@ -77,15 +71,13 @@ async def update_indexes(
@router.delete("/", status_code=204)
async def delete_indexes(
pedimento_id: int,
company_id: int = Query(..., description="Company ID"),
db: Session = Depends(get_core_db),
current_user: dict = Depends(get_current_user)
):
"""Delete pedimento indexes"""
tenant_id = get_tenant_from_token(current_user)
if not tenant_id:
raise HTTPException(status_code=400, detail="Tenant ID not found in token")
tenant_id = validate_access_to_resource(company_id)
success = PedimentoIndexesService.delete(db, pedimento_id, tenant_id)
success = PedimentoIndexesService.delete(db, pedimento_id, tenant_id, company_id)
if not success:
raise HTTPException(status_code=404, detail="Pedimento indexes not found")

View File

@@ -1,11 +1,11 @@
"""
Routes for PedimentoPayments CRUD operations
"""
from fastapi import APIRouter, Depends, HTTPException
from fastapi import APIRouter, Depends, HTTPException, Query
from sqlalchemy.orm import Session
from typing import List
from core.database import get_core_db
from core.security import get_current_user, get_tenant_from_token
from core.security import validate_access_to_resource
from ..services.pedimento_payments import PedimentoPaymentsService
from ..dtos.pedimento_payments import (
@@ -21,15 +21,13 @@ router = APIRouter(prefix="/{pedimento_id}/payments")
@router.get("/", response_model=List[PedimentoPaymentsResponse])
async def list_payments(
pedimento_id: int,
company_id: int = Query(..., description="Company ID"),
db: Session = Depends(get_core_db),
current_user: dict = Depends(get_current_user)
):
"""Get all payments for a pedimento"""
tenant_id = get_tenant_from_token(current_user)
if not tenant_id:
raise HTTPException(status_code=400, detail="Tenant ID not found in token")
tenant_id = validate_access_to_resource(company_id)
payments = PedimentoPaymentsService.get_by_pedimento_id(db, pedimento_id, tenant_id)
payments = PedimentoPaymentsService.get_by_pedimento_id(db, pedimento_id, tenant_id, company_id)
return payments
@@ -37,15 +35,13 @@ async def list_payments(
async def get_payment(
pedimento_id: int,
payment_id: int,
company_id: int = Query(..., description="Company ID"),
db: Session = Depends(get_core_db),
current_user: dict = Depends(get_current_user)
):
"""Get a specific payment by 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")
tenant_id = validate_access_to_resource(company_id)
payment = PedimentoPaymentsService.get_by_id(db, payment_id, pedimento_id, tenant_id)
payment = PedimentoPaymentsService.get_by_id(db, payment_id, pedimento_id, tenant_id, company_id)
if not payment:
raise HTTPException(status_code=404, detail="Payment not found")
@@ -56,19 +52,17 @@ async def get_payment(
async def create_payment(
pedimento_id: int,
data: PedimentoPaymentsCreate,
company_id: int = Query(..., description="Company ID"),
db: Session = Depends(get_core_db),
current_user: dict = Depends(get_current_user)
):
"""Create a new payment"""
tenant_id = get_tenant_from_token(current_user)
if not tenant_id:
raise HTTPException(status_code=400, detail="Tenant ID not found in token")
tenant_id = validate_access_to_resource(company_id)
# Ensure pedimento_id matches
if data.pedimento_id != pedimento_id:
raise HTTPException(status_code=400, detail="Pedimento ID mismatch")
payment = PedimentoPaymentsService.create(db, data, tenant_id)
payment = PedimentoPaymentsService.create(db, data, tenant_id, company_id)
return payment
@@ -77,15 +71,13 @@ async def update_payment(
pedimento_id: int,
payment_id: int,
data: PedimentoPaymentsUpdate,
company_id: int = Query(..., description="Company ID"),
db: Session = Depends(get_core_db),
current_user: dict = Depends(get_current_user)
):
"""Update a payment"""
tenant_id = get_tenant_from_token(current_user)
if not tenant_id:
raise HTTPException(status_code=400, detail="Tenant ID not found in token")
tenant_id = validate_access_to_resource(company_id)
payment = PedimentoPaymentsService.update(db, payment_id, pedimento_id, tenant_id, data)
payment = PedimentoPaymentsService.update(db, payment_id, pedimento_id, tenant_id, company_id, data)
if not payment:
raise HTTPException(status_code=404, detail="Payment not found")
@@ -96,15 +88,13 @@ async def update_payment(
async def delete_payment(
pedimento_id: int,
payment_id: int,
company_id: int = Query(..., description="Company ID"),
db: Session = Depends(get_core_db),
current_user: dict = Depends(get_current_user)
):
"""Delete a payment"""
tenant_id = get_tenant_from_token(current_user)
if not tenant_id:
raise HTTPException(status_code=400, detail="Tenant ID not found in token")
tenant_id = validate_access_to_resource(company_id)
success = PedimentoPaymentsService.delete(db, payment_id, pedimento_id, tenant_id)
success = PedimentoPaymentsService.delete(db, payment_id, pedimento_id, tenant_id, company_id)
if not success:
raise HTTPException(status_code=404, detail="Payment not found")

View File

@@ -1,10 +1,10 @@
"""
Routes for PedimentoRectificationDestination CRUD operations
"""
from fastapi import APIRouter, Depends, HTTPException
from fastapi import APIRouter, Depends, HTTPException, Query
from sqlalchemy.orm import Session
from core.database import get_core_db
from core.security import get_current_user, get_tenant_from_token
from core.security import validate_access_to_resource
from ..services.pedimento_rectification_destination import PedimentoRectificationDestinationService
from ..dtos.pedimento_rectification_destination import (
@@ -20,15 +20,13 @@ router = APIRouter(prefix="/{pedimento_id}/rectification-destination")
@router.get("/", response_model=PedimentoRectificationDestinationResponse)
async def get_rectification_destination(
pedimento_id: int,
company_id: int = Query(..., description="Company ID"),
db: Session = Depends(get_core_db),
current_user: dict = Depends(get_current_user)
):
"""Get rectification destination 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")
tenant_id = validate_access_to_resource(company_id)
rectification = PedimentoRectificationDestinationService.get_by_pedimento_id(db, pedimento_id, tenant_id)
rectification = PedimentoRectificationDestinationService.get_by_pedimento_id(db, pedimento_id, tenant_id, company_id)
if not rectification:
raise HTTPException(status_code=404, detail="Rectification destination not found")
@@ -39,19 +37,17 @@ async def get_rectification_destination(
async def create_rectification_destination(
pedimento_id: int,
data: PedimentoRectificationDestinationCreate,
company_id: int = Query(..., description="Company ID"),
db: Session = Depends(get_core_db),
current_user: dict = Depends(get_current_user)
):
"""Create rectification destination"""
tenant_id = get_tenant_from_token(current_user)
if not tenant_id:
raise HTTPException(status_code=400, detail="Tenant ID not found in token")
tenant_id = validate_access_to_resource(company_id)
# Ensure pedimento_id matches
if data.pedimento_id != pedimento_id:
raise HTTPException(status_code=400, detail="Pedimento ID mismatch")
rectification = PedimentoRectificationDestinationService.create(db, data, tenant_id)
rectification = PedimentoRectificationDestinationService.create(db, data, tenant_id, company_id)
return rectification
@@ -59,15 +55,13 @@ async def create_rectification_destination(
async def update_rectification_destination(
pedimento_id: int,
data: PedimentoRectificationDestinationUpdate,
company_id: int = Query(..., description="Company ID"),
db: Session = Depends(get_core_db),
current_user: dict = Depends(get_current_user)
):
"""Update rectification destination"""
tenant_id = get_tenant_from_token(current_user)
if not tenant_id:
raise HTTPException(status_code=400, detail="Tenant ID not found in token")
tenant_id = validate_access_to_resource(company_id)
rectification = PedimentoRectificationDestinationService.update(db, pedimento_id, tenant_id, data)
rectification = PedimentoRectificationDestinationService.update(db, pedimento_id, tenant_id, company_id, data)
if not rectification:
raise HTTPException(status_code=404, detail="Rectification destination not found")
@@ -77,15 +71,13 @@ async def update_rectification_destination(
@router.delete("/", status_code=204)
async def delete_rectification_destination(
pedimento_id: int,
company_id: int = Query(..., description="Company ID"),
db: Session = Depends(get_core_db),
current_user: dict = Depends(get_current_user)
):
"""Delete rectification destination"""
tenant_id = get_tenant_from_token(current_user)
if not tenant_id:
raise HTTPException(status_code=400, detail="Tenant ID not found in token")
tenant_id = validate_access_to_resource(company_id)
success = PedimentoRectificationDestinationService.delete(db, pedimento_id, tenant_id)
success = PedimentoRectificationDestinationService.delete(db, pedimento_id, tenant_id, company_id)
if not success:
raise HTTPException(status_code=404, detail="Rectification destination not found")

View File

@@ -1,10 +1,10 @@
"""
Routes for PedimentoRectificationOrigin CRUD operations
"""
from fastapi import APIRouter, Depends, HTTPException
from fastapi import APIRouter, Depends, HTTPException, Query
from sqlalchemy.orm import Session
from core.database import get_core_db
from core.security import get_current_user, get_tenant_from_token
from core.security import validate_access_to_resource
from ..services.pedimento_rectification_origin import PedimentoRectificationOriginService
from ..dtos.pedimento_rectification_origin import (
@@ -20,15 +20,13 @@ router = APIRouter(prefix="/{pedimento_id}/rectification-origin")
@router.get("/", response_model=PedimentoRectificationOriginResponse)
async def get_rectification_origin(
pedimento_id: int,
company_id: int = Query(..., description="Company ID"),
db: Session = Depends(get_core_db),
current_user: dict = Depends(get_current_user)
):
"""Get rectification origin 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")
tenant_id = validate_access_to_resource(company_id)
rectification = PedimentoRectificationOriginService.get_by_pedimento_id(db, pedimento_id, tenant_id)
rectification = PedimentoRectificationOriginService.get_by_pedimento_id(db, pedimento_id, tenant_id, company_id)
if not rectification:
raise HTTPException(status_code=404, detail="Rectification origin not found")
@@ -39,19 +37,17 @@ async def get_rectification_origin(
async def create_rectification_origin(
pedimento_id: int,
data: PedimentoRectificationOriginCreate,
company_id: int = Query(..., description="Company ID"),
db: Session = Depends(get_core_db),
current_user: dict = Depends(get_current_user)
):
"""Create rectification origin"""
tenant_id = get_tenant_from_token(current_user)
if not tenant_id:
raise HTTPException(status_code=400, detail="Tenant ID not found in token")
tenant_id = validate_access_to_resource(company_id)
# Ensure pedimento_id matches
if data.pedimento_id != pedimento_id:
raise HTTPException(status_code=400, detail="Pedimento ID mismatch")
rectification = PedimentoRectificationOriginService.create(db, data, tenant_id)
rectification = PedimentoRectificationOriginService.create(db, data, tenant_id, company_id)
return rectification
@@ -59,15 +55,13 @@ async def create_rectification_origin(
async def update_rectification_origin(
pedimento_id: int,
data: PedimentoRectificationOriginUpdate,
company_id: int = Query(..., description="Company ID"),
db: Session = Depends(get_core_db),
current_user: dict = Depends(get_current_user)
):
"""Update rectification origin"""
tenant_id = get_tenant_from_token(current_user)
if not tenant_id:
raise HTTPException(status_code=400, detail="Tenant ID not found in token")
tenant_id = validate_access_to_resource(company_id)
rectification = PedimentoRectificationOriginService.update(db, pedimento_id, tenant_id, data)
rectification = PedimentoRectificationOriginService.update(db, pedimento_id, tenant_id, company_id, data)
if not rectification:
raise HTTPException(status_code=404, detail="Rectification origin not found")
@@ -77,15 +71,13 @@ async def update_rectification_origin(
@router.delete("/", status_code=204)
async def delete_rectification_origin(
pedimento_id: int,
company_id: int = Query(..., description="Company ID"),
db: Session = Depends(get_core_db),
current_user: dict = Depends(get_current_user)
):
"""Delete rectification origin"""
tenant_id = get_tenant_from_token(current_user)
if not tenant_id:
raise HTTPException(status_code=400, detail="Tenant ID not found in token")
tenant_id = validate_access_to_resource(company_id)
success = PedimentoRectificationOriginService.delete(db, pedimento_id, tenant_id)
success = PedimentoRectificationOriginService.delete(db, pedimento_id, tenant_id, company_id)
if not success:
raise HTTPException(status_code=404, detail="Rectification origin not found")

View File

@@ -1,11 +1,11 @@
"""
Routes for PedimentoTransportMeans CRUD operations
"""
from fastapi import APIRouter, Depends, HTTPException
from fastapi import APIRouter, Depends, HTTPException, Query
from sqlalchemy.orm import Session
from typing import List
from core.database import get_core_db
from core.security import get_current_user, get_tenant_from_token
from core.security import validate_access_to_resource
from ..services.pedimento_transport_means import PedimentoTransportMeansService
from ..dtos.pedimento_transport_means import (
@@ -21,15 +21,13 @@ router = APIRouter(prefix="/{pedimento_id}/transport-means")
@router.get("/", response_model=List[PedimentoTransportMeansResponse])
async def list_transport_means(
pedimento_id: int,
company_id: int = Query(..., description="Company ID"),
db: Session = Depends(get_core_db),
current_user: dict = Depends(get_current_user)
):
"""Get all transport means for a pedimento"""
tenant_id = get_tenant_from_token(current_user)
if not tenant_id:
raise HTTPException(status_code=400, detail="Tenant ID not found in token")
tenant_id = validate_access_to_resource(company_id)
transport_means = PedimentoTransportMeansService.get_by_pedimento_id(db, pedimento_id, tenant_id)
transport_means = PedimentoTransportMeansService.get_by_pedimento_id(db, pedimento_id, tenant_id, company_id)
return transport_means
@@ -37,15 +35,13 @@ async def list_transport_means(
async def get_transport_mean(
pedimento_id: int,
transport_mean_id: int,
company_id: int = Query(..., description="Company ID"),
db: Session = Depends(get_core_db),
current_user: dict = Depends(get_current_user)
):
"""Get a specific transport mean by 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")
tenant_id = validate_access_to_resource(company_id)
transport_mean = PedimentoTransportMeansService.get_by_id(db, transport_mean_id, pedimento_id, tenant_id)
transport_mean = PedimentoTransportMeansService.get_by_id(db, transport_mean_id, pedimento_id, tenant_id, company_id)
if not transport_mean:
raise HTTPException(status_code=404, detail="Transport mean not found")
@@ -56,19 +52,17 @@ async def get_transport_mean(
async def create_transport_mean(
pedimento_id: int,
data: PedimentoTransportMeansCreate,
company_id: int = Query(..., description="Company ID"),
db: Session = Depends(get_core_db),
current_user: dict = Depends(get_current_user)
):
"""Create a new transport mean"""
tenant_id = get_tenant_from_token(current_user)
if not tenant_id:
raise HTTPException(status_code=400, detail="Tenant ID not found in token")
tenant_id = validate_access_to_resource(company_id)
# Ensure pedimento_id matches
if data.pedimento_id != pedimento_id:
raise HTTPException(status_code=400, detail="Pedimento ID mismatch")
transport_mean = PedimentoTransportMeansService.create(db, data, tenant_id)
transport_mean = PedimentoTransportMeansService.create(db, data, tenant_id, company_id)
return transport_mean
@@ -77,15 +71,13 @@ async def update_transport_mean(
pedimento_id: int,
transport_mean_id: int,
data: PedimentoTransportMeansUpdate,
company_id: int = Query(..., description="Company ID"),
db: Session = Depends(get_core_db),
current_user: dict = Depends(get_current_user)
):
"""Update a transport mean"""
tenant_id = get_tenant_from_token(current_user)
if not tenant_id:
raise HTTPException(status_code=400, detail="Tenant ID not found in token")
tenant_id = validate_access_to_resource(company_id)
transport_mean = PedimentoTransportMeansService.update(db, transport_mean_id, pedimento_id, tenant_id, data)
transport_mean = PedimentoTransportMeansService.update(db, transport_mean_id, pedimento_id, tenant_id, company_id, data)
if not transport_mean:
raise HTTPException(status_code=404, detail="Transport mean not found")
@@ -96,15 +88,13 @@ async def update_transport_mean(
async def delete_transport_mean(
pedimento_id: int,
transport_mean_id: int,
company_id: int = Query(..., description="Company ID"),
db: Session = Depends(get_core_db),
current_user: dict = Depends(get_current_user)
):
"""Delete a transport mean"""
tenant_id = get_tenant_from_token(current_user)
if not tenant_id:
raise HTTPException(status_code=400, detail="Tenant ID not found in token")
tenant_id = validate_access_to_resource(company_id)
success = PedimentoTransportMeansService.delete(db, transport_mean_id, pedimento_id, tenant_id)
success = PedimentoTransportMeansService.delete(db, transport_mean_id, pedimento_id, tenant_id, company_id)
if not success:
raise HTTPException(status_code=404, detail="Transport mean not found")

View File

@@ -1,10 +1,10 @@
"""
Routes for PedimentoValidation CRUD operations
"""
from fastapi import APIRouter, Depends, HTTPException
from fastapi import APIRouter, Depends, HTTPException, Query
from sqlalchemy.orm import Session
from core.database import get_core_db
from core.security import get_current_user, get_tenant_from_token
from core.security import validate_access_to_resource
from ..services.pedimento_validation import PedimentoValidationService
from ..dtos.pedimento_validation import (
@@ -20,15 +20,13 @@ router = APIRouter(prefix="/{pedimento_id}/validation")
@router.get("/", response_model=PedimentoValidationResponse)
async def get_validation(
pedimento_id: int,
company_id: int = Query(..., description="Company ID"),
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")
tenant_id = validate_access_to_resource(company_id)
validation = PedimentoValidationService.get_by_pedimento_id(db, pedimento_id, tenant_id)
validation = PedimentoValidationService.get_by_pedimento_id(db, pedimento_id, tenant_id, company_id)
if not validation:
raise HTTPException(status_code=404, detail="Pedimento validation not found")
@@ -39,19 +37,17 @@ async def get_validation(
async def create_validation(
pedimento_id: int,
data: PedimentoValidationCreate,
company_id: int = Query(..., description="Company ID"),
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")
tenant_id = validate_access_to_resource(company_id)
# 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)
validation = PedimentoValidationService.create(db, data, tenant_id, company_id)
return validation
@@ -59,15 +55,13 @@ async def create_validation(
async def update_validation(
pedimento_id: int,
data: PedimentoValidationUpdate,
company_id: int = Query(..., description="Company ID"),
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")
tenant_id = validate_access_to_resource(company_id)
validation = PedimentoValidationService.update(db, pedimento_id, tenant_id, data)
validation = PedimentoValidationService.update(db, pedimento_id, tenant_id, company_id, data)
if not validation:
raise HTTPException(status_code=404, detail="Pedimento validation not found")
@@ -77,15 +71,13 @@ async def update_validation(
@router.delete("/", status_code=204)
async def delete_validation(
pedimento_id: int,
company_id: int = Query(..., description="Company ID"),
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")
tenant_id = validate_access_to_resource(company_id)
success = PedimentoValidationService.delete(db, pedimento_id, tenant_id)
success = PedimentoValidationService.delete(db, pedimento_id, tenant_id, company_id)
if not success:
raise HTTPException(status_code=404, detail="Pedimento validation not found")

View File

@@ -5,7 +5,7 @@ from fastapi import APIRouter, Depends, HTTPException, Query
from sqlalchemy.orm import Session
from typing import Dict, Any, Optional
from core.database import get_core_db
from core.security import get_current_user, get_tenant_from_token
from core.security import validate_access_to_resource
from ..services.pedimentos import PedimentosService
from ..dtos.pedimentos import PedimentosCreate, PedimentosUpdate, PedimentosResponse
@@ -16,18 +16,16 @@ router = APIRouter()
@router.get("/", response_model=Dict[str, Any])
async def list_pedimentos(
company_id: int = Query(..., description="Company ID"),
page: int = Query(1, ge=1, description="Page number"),
page_size: int = Query(50, ge=1, le=100, description="Page size"),
status: Optional[str] = Query(None, description="Filter by status"),
client_id: Optional[int] = Query(None, description="Filter by client ID"),
year: Optional[str] = Query(None, description="Filter by year"),
db: Session = Depends(get_core_db),
current_user: dict = Depends(get_current_user)
):
"""Get all pedimentos with pagination and filters"""
tenant_id = get_tenant_from_token(current_user)
if not tenant_id:
raise HTTPException(status_code=400, detail="Tenant ID not found in token")
tenant_id = validate_access_to_resource(company_id)
filters = {}
if status:
@@ -38,7 +36,7 @@ async def list_pedimentos(
filters["year"] = year
skip = (page - 1) * page_size
items, total = PedimentosService.get_all(db, tenant_id, skip, page_size, filters)
items, total = PedimentosService.get_all(db, tenant_id, company_id, skip, page_size, filters)
return {
"items": [PedimentosResponse.model_validate(item) for item in items],
@@ -51,15 +49,13 @@ async def list_pedimentos(
@router.get("/{pedimento_id}", response_model=PedimentosResponse)
async def get_pedimento(
pedimento_id: int,
company_id: int = Query(..., description="Company ID"),
db: Session = Depends(get_core_db),
current_user: dict = Depends(get_current_user)
):
"""Get a pedimento by 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")
tenant_id = validate_access_to_resource(company_id)
pedimento = PedimentosService.get_by_id(db, pedimento_id, tenant_id)
pedimento = PedimentosService.get_by_id(db, pedimento_id, tenant_id, company_id)
if not pedimento:
raise HTTPException(status_code=404, detail="Pedimento not found")
@@ -69,15 +65,13 @@ async def get_pedimento(
@router.post("/", response_model=PedimentosResponse, status_code=201)
async def create_pedimento(
data: PedimentosCreate,
company_id: int = Query(..., description="Company ID"),
db: Session = Depends(get_core_db),
current_user: dict = Depends(get_current_user)
):
"""Create a new pedimento"""
tenant_id = get_tenant_from_token(current_user)
if not tenant_id:
raise HTTPException(status_code=400, detail="Tenant ID not found in token")
tenant_id = validate_access_to_resource(company_id)
pedimento = PedimentosService.create(db, data, tenant_id)
pedimento = PedimentosService.create(db, data, tenant_id, company_id)
return pedimento
@@ -85,15 +79,13 @@ async def create_pedimento(
async def update_pedimento(
pedimento_id: int,
data: PedimentosUpdate,
company_id: int = Query(..., description="Company ID"),
db: Session = Depends(get_core_db),
current_user: dict = Depends(get_current_user)
):
"""Update a pedimento"""
tenant_id = get_tenant_from_token(current_user)
if not tenant_id:
raise HTTPException(status_code=400, detail="Tenant ID not found in token")
tenant_id = validate_access_to_resource(company_id)
pedimento = PedimentosService.update(db, pedimento_id, tenant_id, data)
pedimento = PedimentosService.update(db, pedimento_id, tenant_id, company_id, data)
if not pedimento:
raise HTTPException(status_code=404, detail="Pedimento not found")
@@ -103,15 +95,13 @@ async def update_pedimento(
@router.delete("/{pedimento_id}", status_code=204)
async def delete_pedimento(
pedimento_id: int,
company_id: int = Query(..., description="Company ID"),
db: Session = Depends(get_core_db),
current_user: dict = Depends(get_current_user)
):
"""Delete a pedimento"""
tenant_id = get_tenant_from_token(current_user)
if not tenant_id:
raise HTTPException(status_code=400, detail="Tenant ID not found in token")
tenant_id = validate_access_to_resource(company_id)
success = PedimentosService.delete(db, pedimento_id, tenant_id)
success = PedimentosService.delete(db, pedimento_id, tenant_id, company_id)
if not success:
raise HTTPException(status_code=404, detail="Pedimento not found")

View File

@@ -12,17 +12,21 @@ class PedimentoConfigAdditionalService:
"""Service class for PedimentoConfigAdditional business logic"""
@staticmethod
def get_by_pedimento_id(db: Session, pedimento_id: int, tenant_id: int) -> Optional[PedimentoConfigAdditional]:
def get_by_pedimento_id(db: Session, pedimento_id: int, tenant_id: int, company_id: int) -> Optional[PedimentoConfigAdditional]:
"""Get config by pedimento ID"""
return db.query(PedimentoConfigAdditional).filter(
PedimentoConfigAdditional.pedimento_id == pedimento_id,
PedimentoConfigAdditional.tenant_id == tenant_id
PedimentoConfigAdditional.tenant_id == tenant_id,
PedimentoConfigAdditional.company_id == company_id
).first()
@staticmethod
def create(db: Session, config_data: PedimentoConfigAdditionalCreate) -> PedimentoConfigAdditional:
def create(db: Session, config_data: PedimentoConfigAdditionalCreate, tenant_id: int, company_id: int) -> PedimentoConfigAdditional:
"""Create a new config"""
config = PedimentoConfigAdditional(**config_data.model_dump())
config.tenant_id = tenant_id
config.company_id = company_id
db.add(config)
db.commit()
db.refresh(config)
@@ -33,10 +37,11 @@ class PedimentoConfigAdditionalService:
db: Session,
pedimento_id: int,
tenant_id: int,
company_id: int,
config_data: PedimentoConfigAdditionalUpdate
) -> Optional[PedimentoConfigAdditional]:
"""Update config"""
config = PedimentoConfigAdditionalService.get_by_pedimento_id(db, pedimento_id, tenant_id)
config = PedimentoConfigAdditionalService.get_by_pedimento_id(db, pedimento_id, tenant_id, company_id)
if not config:
return None
@@ -49,9 +54,9 @@ class PedimentoConfigAdditionalService:
return config
@staticmethod
def delete(db: Session, pedimento_id: int, tenant_id: int) -> bool:
def delete(db: Session, pedimento_id: int, tenant_id: int, company_id: int) -> bool:
"""Delete config"""
config = PedimentoConfigAdditionalService.get_by_pedimento_id(db, pedimento_id, tenant_id)
config = PedimentoConfigAdditionalService.get_by_pedimento_id(db, pedimento_id, tenant_id, company_id)
if not config:
return False

View File

@@ -12,17 +12,21 @@ class PedimentoConfigCalculationsService:
"""Service class for PedimentoConfigCalculations business logic"""
@staticmethod
def get_by_pedimento_id(db: Session, pedimento_id: int, tenant_id: int) -> Optional[PedimentoConfigCalculations]:
def get_by_pedimento_id(db: Session, pedimento_id: int, tenant_id: int, company_id: int) -> Optional[PedimentoConfigCalculations]:
"""Get config by pedimento ID"""
return db.query(PedimentoConfigCalculations).filter(
PedimentoConfigCalculations.pedimento_id == pedimento_id,
PedimentoConfigCalculations.tenant_id == tenant_id
PedimentoConfigCalculations.tenant_id == tenant_id,
PedimentoConfigCalculations.company_id == company_id
).first()
@staticmethod
def create(db: Session, config_data: PedimentoConfigCalculationsCreate) -> PedimentoConfigCalculations:
def create(db: Session, config_data: PedimentoConfigCalculationsCreate, tenant_id: int, company_id: int) -> PedimentoConfigCalculations:
"""Create a new config"""
config = PedimentoConfigCalculations(**config_data.model_dump())
config.tenant_id = tenant_id
config.company_id = company_id
db.add(config)
db.commit()
db.refresh(config)
@@ -33,10 +37,11 @@ class PedimentoConfigCalculationsService:
db: Session,
pedimento_id: int,
tenant_id: int,
company_id: int,
config_data: PedimentoConfigCalculationsUpdate
) -> Optional[PedimentoConfigCalculations]:
"""Update config"""
config = PedimentoConfigCalculationsService.get_by_pedimento_id(db, pedimento_id, tenant_id)
config = PedimentoConfigCalculationsService.get_by_pedimento_id(db, pedimento_id, tenant_id, company_id)
if not config:
return None
@@ -49,9 +54,9 @@ class PedimentoConfigCalculationsService:
return config
@staticmethod
def delete(db: Session, pedimento_id: int, tenant_id: int) -> bool:
def delete(db: Session, pedimento_id: int, tenant_id: int, company_id: int) -> bool:
"""Delete config"""
config = PedimentoConfigCalculationsService.get_by_pedimento_id(db, pedimento_id, tenant_id)
config = PedimentoConfigCalculationsService.get_by_pedimento_id(db, pedimento_id, tenant_id, company_id)
if not config:
return False