| 123456789101112131415161718192021222324252627282930313233 |
- """客户装/送货物流默认记忆 API"""
- from typing import Optional
- from fastapi import APIRouter, Depends, HTTPException, Query
- from sqlalchemy.orm import Session
- from app.core.database import get_db
- from app.core.db_auth import DbUserContext, get_db_current_user
- from app.core.tenant_context import get_tenant_no
- from app.schemas.pl.customer_stop_pref import CustomerStopPrefRead
- from app.services.pl_customer_stop_pref_service import (
- STOP_DELIVERY,
- STOP_LOAD,
- get_customer_stop_pref,
- )
- router = APIRouter(tags=["客户装卸货默认记忆"])
- @router.get("/customer-stop-pref", response_model=Optional[CustomerStopPrefRead])
- def read_customer_stop_pref(
- customer_id: str = Query(..., alias="customerId"),
- stop_type: str = Query(..., alias="stopType", description="load | delivery"),
- db: Session = Depends(get_db),
- user: DbUserContext = Depends(get_db_current_user),
- ) -> Optional[CustomerStopPrefRead]:
- if stop_type not in (STOP_LOAD, STOP_DELIVERY):
- raise HTTPException(status_code=400, detail="stopType 须为 load 或 delivery")
- tenant_no = get_tenant_no(db, user.to_tenant_user_dict())
- row = get_customer_stop_pref(db, tenant_no, customer_id, stop_type)
- if not row:
- return None
- return CustomerStopPrefRead.model_validate(row)
|