Resumen del trabajo de hoy: Se agregaron y actualizaron módulos, rutas, servicios y DTOs para las entidades trabajadas hoy, incluyendo Aduanal, Drivers, Trailers, TransportModes, TransportTypes, Transporters, Vehicles, entre otros. Se verificó la presencia de los campos tenant_id y company_id en los modelos relevantes.
This commit is contained in:
22
backend/api/v1/modules/a76/trailers/dto.py
Normal file
22
backend/api/v1/modules/a76/trailers/dto.py
Normal file
@@ -0,0 +1,22 @@
|
||||
from pydantic import BaseModel
|
||||
from typing import Optional
|
||||
|
||||
class TrailerBaseDTO(BaseModel):
|
||||
trailer_number: str
|
||||
ace_trailer_number: Optional[str]
|
||||
trailer_type_key: Optional[str]
|
||||
seal: Optional[str]
|
||||
entity_code: Optional[str]
|
||||
plate_number: Optional[str]
|
||||
state: Optional[str]
|
||||
country: Optional[str]
|
||||
container_key: Optional[str]
|
||||
company_id: str
|
||||
tenant_id: str
|
||||
|
||||
class TrailerCreateDTO(TrailerBaseDTO):
|
||||
pass
|
||||
|
||||
class TrailerResponseDTO(TrailerBaseDTO):
|
||||
class Config:
|
||||
orm_mode = True
|
||||
18
backend/api/v1/modules/a76/trailers/models.py
Normal file
18
backend/api/v1/modules/a76/trailers/models.py
Normal file
@@ -0,0 +1,18 @@
|
||||
from sqlalchemy import Column, String, ForeignKey
|
||||
from core.database import Base
|
||||
|
||||
class Trailer(Base):
|
||||
__tablename__ = "trailer"
|
||||
__table_args__ = {"schema": "a76"}
|
||||
|
||||
trailer_number = Column(String(20), primary_key=True, nullable=False)
|
||||
ace_trailer_number = Column(String(10), nullable=True)
|
||||
trailer_type_key = Column(String(2), ForeignKey("a76.trailer_type.trailer_type_key"), nullable=True)
|
||||
seal = Column(String(15), nullable=True)
|
||||
entity_code = Column(String(1), nullable=True)
|
||||
plate_number = Column(String(17), nullable=True)
|
||||
state = Column(String(30), nullable=True)
|
||||
country = Column(String(3), nullable=True)
|
||||
container_key = Column(String(3), nullable=True)
|
||||
company_id = Column(String, ForeignKey("a76.company.id"), nullable=False)
|
||||
tenant_id = Column(String, ForeignKey("a76.tenants.id"), nullable=False)
|
||||
24
backend/api/v1/modules/a76/trailers/routes.py
Normal file
24
backend/api/v1/modules/a76/trailers/routes.py
Normal file
@@ -0,0 +1,24 @@
|
||||
from fastapi import APIRouter, Depends, HTTPException
|
||||
from sqlalchemy.orm import Session
|
||||
from . import services, dto
|
||||
from core.database import get_db
|
||||
|
||||
router = APIRouter()
|
||||
|
||||
@router.get("/trailers/{trailer_number}", response_model=dto.TrailerDTO)
|
||||
def get_trailer(trailer_number: str, db: Session = Depends(get_db)):
|
||||
trailer = services.TrailerService.get_trailer_by_number(db, trailer_number)
|
||||
if not trailer:
|
||||
raise HTTPException(status_code=404, detail="Trailer not found")
|
||||
return trailer
|
||||
|
||||
@router.post("/trailers", response_model=dto.TrailerDTO)
|
||||
def create_trailer(trailer_data: dto.TrailerCreateDTO, db: Session = Depends(get_db)):
|
||||
return services.TrailerService.create_trailer(db, trailer_data)
|
||||
|
||||
@router.delete("/trailers/{trailer_number}", response_model=dto.TrailerDTO)
|
||||
def delete_trailer(trailer_number: str, db: Session = Depends(get_db)):
|
||||
trailer = services.TrailerService.delete_trailer(db, trailer_number)
|
||||
if not trailer:
|
||||
raise HTTPException(status_code=404, detail="Trailer not found")
|
||||
return trailer
|
||||
23
backend/api/v1/modules/a76/trailers/services.py
Normal file
23
backend/api/v1/modules/a76/trailers/services.py
Normal file
@@ -0,0 +1,23 @@
|
||||
from sqlalchemy.orm import Session
|
||||
from . import models, dto
|
||||
|
||||
class TrailerService:
|
||||
@staticmethod
|
||||
def get_trailer_by_number(db: Session, trailer_number: str):
|
||||
return db.query(models.Trailer).filter(models.Trailer.trailer_number == trailer_number).first()
|
||||
|
||||
@staticmethod
|
||||
def create_trailer(db: Session, trailer_data: dto.TrailerCreateDTO):
|
||||
new_trailer = models.Trailer(**trailer_data.dict())
|
||||
db.add(new_trailer)
|
||||
db.commit()
|
||||
db.refresh(new_trailer)
|
||||
return new_trailer
|
||||
|
||||
@staticmethod
|
||||
def delete_trailer(db: Session, trailer_number: str):
|
||||
trailer = TrailerService.get_trailer_by_number(db, trailer_number)
|
||||
if trailer:
|
||||
db.delete(trailer)
|
||||
db.commit()
|
||||
return trailer
|
||||
Reference in New Issue
Block a user