customer_stop_pref.py 1.3 KB

123456789101112131415161718192021222324252627282930313233
  1. """客户装/送货物流默认记忆 API"""
  2. from typing import Optional
  3. from fastapi import APIRouter, Depends, HTTPException, Query
  4. from sqlalchemy.orm import Session
  5. from app.core.database import get_db
  6. from app.core.db_auth import DbUserContext, get_db_current_user
  7. from app.core.tenant_context import get_tenant_no
  8. from app.schemas.pl.customer_stop_pref import CustomerStopPrefRead
  9. from app.services.pl_customer_stop_pref_service import (
  10. STOP_DELIVERY,
  11. STOP_LOAD,
  12. get_customer_stop_pref,
  13. )
  14. router = APIRouter(tags=["客户装卸货默认记忆"])
  15. @router.get("/customer-stop-pref", response_model=Optional[CustomerStopPrefRead])
  16. def read_customer_stop_pref(
  17. customer_id: str = Query(..., alias="customerId"),
  18. stop_type: str = Query(..., alias="stopType", description="load | delivery"),
  19. db: Session = Depends(get_db),
  20. user: DbUserContext = Depends(get_db_current_user),
  21. ) -> Optional[CustomerStopPrefRead]:
  22. if stop_type not in (STOP_LOAD, STOP_DELIVERY):
  23. raise HTTPException(status_code=400, detail="stopType 须为 load 或 delivery")
  24. tenant_no = get_tenant_no(db, user.to_tenant_user_dict())
  25. row = get_customer_stop_pref(db, tenant_no, customer_id, stop_type)
  26. if not row:
  27. return None
  28. return CustomerStopPrefRead.model_validate(row)