Refactor backend and frontend code for improved structure and functionality

- Rearranged imports in multiple files for consistency and clarity.
- Updated logging middleware to exclude specific paths from logging.
- Enhanced security module by cleaning up token handling and improving tenant validation.
- Added tenant and company scoped mixins for better database model management.
- Implemented generic CRUD routes for tenant-scoped resources.
- Improved error handling and response management in API routes.
- Cleaned up login and logout processes to ensure proper session management.
- Introduced mechanisms to clear local storage and cookies on tenant change.
- Enhanced company store to detect tenant changes and clear data accordingly.
- Added new DTO mixins for currency and value affect flags.
This commit is contained in:
2025-11-11 17:20:47 -06:00
parent ac7f8d19d8
commit b68c4316ff
247 changed files with 2248 additions and 2504 deletions

View File

@@ -1,6 +1,8 @@
from pydantic import BaseModel
from typing import Optional
from pydantic import BaseModel
class TrailerBaseDTO(BaseModel):
trailer_number: str
ace_trailer_number: Optional[str]
@@ -14,9 +16,11 @@ class TrailerBaseDTO(BaseModel):
company_id: str
tenant_id: str
class TrailerCreateDTO(TrailerBaseDTO):
pass
class TrailerResponseDTO(TrailerBaseDTO):
class Config:
from_attributes = True
from_attributes = True

View File

@@ -1,18 +1,24 @@
from sqlalchemy import Column, Integer, String, ForeignKey
from api.v1.common.base_models import TenantScopedMixin
from core.database import Base
from sqlalchemy import Column, ForeignKey, ForeignKeyConstraint, String
class Trailer(Base):
class Trailer(Base, TenantScopedMixin):
__tablename__ = "trailer"
__table_args__ = {"schema": "a76"}
__table_args__ = (
ForeignKeyConstraint(["company_id"], ["a76.company.id"]),
ForeignKeyConstraint(["tenant_id"], ["a76.tenants.id"]),
{"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)
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(Integer, ForeignKey("a76.company.id"), nullable=False)
tenant_id = Column(Integer, ForeignKey("a76.tenants.id"), nullable=False)

View File

@@ -1,10 +1,12 @@
from core.database import get_core_db
from fastapi import APIRouter, Depends, HTTPException
from sqlalchemy.orm import Session
from . import services, dto
from core.database import get_core_db
from . import dto, services
router = APIRouter()
@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)
@@ -12,13 +14,17 @@ def get_trailer(trailer_number: str, db: Session = Depends(get_core_db)):
raise HTTPException(status_code=404, detail="Trailer not found")
return trailer
@router.post("/trailers", response_model=dto.TrailerResponseDTO)
def create_trailer(trailer_data: dto.TrailerCreateDTO, db: Session = Depends(get_core_db)):
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.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")
return trailer
return trailer

View File

@@ -1,10 +1,16 @@
from sqlalchemy.orm import Session
from . import models, dto
from . import dto, models
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()
return (
db.query(models.Trailer)
.filter(models.Trailer.trailer_number == trailer_number)
.first()
)
@staticmethod
def create_trailer(db: Session, trailer_data: dto.TrailerCreateDTO):
@@ -20,4 +26,4 @@ class TrailerService:
if trailer:
db.delete(trailer)
db.commit()
return trailer
return trailer