feat: Refactor DTOs and models to use from_attributes, update database schema references, and implement trailer types
This commit is contained in:
@@ -19,4 +19,4 @@ class TrailerCreateDTO(TrailerBaseDTO):
|
||||
|
||||
class TrailerResponseDTO(TrailerBaseDTO):
|
||||
class Config:
|
||||
orm_mode = True
|
||||
from_attributes = True
|
||||
@@ -1,4 +1,4 @@
|
||||
from sqlalchemy import Column, String, ForeignKey
|
||||
from sqlalchemy import Column, Integer, String, ForeignKey
|
||||
from core.database import Base
|
||||
|
||||
class Trailer(Base):
|
||||
@@ -14,5 +14,5 @@ class Trailer(Base):
|
||||
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)
|
||||
company_id = Column(Integer, ForeignKey("a76.company.id"), nullable=False)
|
||||
tenant_id = Column(Integer, ForeignKey("a76.tenants.id"), nullable=False)
|
||||
@@ -1,23 +1,23 @@
|
||||
from fastapi import APIRouter, Depends, HTTPException
|
||||
from sqlalchemy.orm import Session
|
||||
from . import services, dto
|
||||
from core.database import get_db
|
||||
from core.database import get_core_db
|
||||
|
||||
router = APIRouter()
|
||||
|
||||
@router.get("/trailers/{trailer_number}", response_model=dto.TrailerDTO)
|
||||
def get_trailer(trailer_number: str, db: Session = Depends(get_db)):
|
||||
@router.get("/trailers/{trailer_number}", response_model=dto.TrailerResponseDTO)
|
||||
def get_trailer(trailer_number: str, db: Session = Depends(get_core_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)):
|
||||
@router.post("/trailers", response_model=dto.TrailerResponseDTO)
|
||||
def create_trailer(trailer_data: dto.TrailerCreateDTO, db: Session = Depends(get_core_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)):
|
||||
@router.delete("/trailers/{trailer_number}", response_model=dto.TrailerResponseDTO)
|
||||
def delete_trailer(trailer_number: str, db: Session = Depends(get_core_db)):
|
||||
trailer = services.TrailerService.delete_trailer(db, trailer_number)
|
||||
if not trailer:
|
||||
raise HTTPException(status_code=404, detail="Trailer not found")
|
||||
|
||||
Reference in New Issue
Block a user