- Updated GBultoService to use models.Package instead of models.GBulto. - Refactored Part model to use SQLAlchemy 2.0 style with Mapped and mapped_column. - Added timestamps (created_at, updated_at, deleted_at) to various pedimento models. - Improved relationships and foreign key constraints in pedimento models. - Updated PermissionRuleOct and Seal models to use Mapped and mapped_column. - Changed DTO configuration from orm_mode to from_attributes for better compatibility. - Removed obsolete models (models.py and models_ped.py) from the repository.
81 lines
2.3 KiB
Python
81 lines
2.3 KiB
Python
from fastapi import APIRouter, Depends, HTTPException, status
|
|
from sqlalchemy.orm import Session
|
|
from typing import List
|
|
|
|
from core.database import get_core_db
|
|
from core.security import get_current_user
|
|
from .models import Package
|
|
from .dto import GBultoCreateDTO, GBultoUpdateDTO, GBultoResponseDTO
|
|
from .services import GBultoService
|
|
|
|
router = APIRouter(prefix="/bultos", tags=["GBultos"])
|
|
|
|
|
|
@router.get("/", response_model=List[GBultoResponseDTO])
|
|
async def list_bultos(
|
|
skip: int = 0,
|
|
limit: int = 100,
|
|
db: Session = Depends(get_core_db),
|
|
current_user: dict = Depends(get_current_user)
|
|
):
|
|
"""
|
|
List all GBultos with pagination.
|
|
"""
|
|
return db.query(Package).offset(skip).limit(limit).all()
|
|
|
|
|
|
@router.get("/{code}", response_model=GBultoResponseDTO)
|
|
async def read_bulto(
|
|
code: str,
|
|
db: Session = Depends(get_core_db),
|
|
current_user: dict = Depends(get_current_user)
|
|
):
|
|
"""
|
|
Get a specific Package by its CODE.
|
|
"""
|
|
bulto = GBultoService.get_bulto_by_code(db, code)
|
|
if not bulto:
|
|
raise HTTPException(status_code=404, detail="Package not found")
|
|
return bulto
|
|
|
|
|
|
@router.post("/", response_model=GBultoResponseDTO, status_code=status.HTTP_201_CREATED)
|
|
async def create_gbulto(
|
|
bulto_data: GBultoCreateDTO,
|
|
db: Session = Depends(get_core_db),
|
|
current_user: dict = Depends(get_current_user)
|
|
):
|
|
"""
|
|
Create a new Package.
|
|
"""
|
|
return GBultoService.create_gbulto(db, bulto_data)
|
|
|
|
|
|
@router.put("/{code}", response_model=GBultoResponseDTO)
|
|
async def update_bulto(
|
|
code: str,
|
|
bulto_data: GBultoUpdateDTO,
|
|
db: Session = Depends(get_core_db),
|
|
current_user: dict = Depends(get_current_user)
|
|
):
|
|
"""
|
|
Update an existing Package.
|
|
"""
|
|
bulto = GBultoService.update_bulto(db, code, bulto_data)
|
|
if not bulto:
|
|
raise HTTPException(status_code=404, detail="Package not found")
|
|
return bulto
|
|
|
|
|
|
@router.delete("/{code}", status_code=status.HTTP_204_NO_CONTENT)
|
|
async def delete_bulto(
|
|
code: str,
|
|
db: Session = Depends(get_core_db),
|
|
current_user: dict = Depends(get_current_user)
|
|
):
|
|
"""
|
|
Delete a Package by its CODE.
|
|
"""
|
|
bulto = GBultoService.delete_bulto(db, code)
|
|
if not bulto:
|
|
raise HTTPException(status_code=404, detail="Package not found") |