Files
fastAPI/app/api/v1/location.py
2026-05-15 08:45:18 +08:00

56 lines
1.5 KiB
Python

from fastapi import APIRouter, Depends
from sqlalchemy.orm import Session
from app.core.database import get_db
from app.schemas.common import ErrorResponse
from app.schemas.location import (
LocationRequest,
LocationResponse,
PaichaOverviewResponse,
)
from app.services.location_service import get_paicha_overview, register_location
router = APIRouter()
@router.post(
"/location",
response_model=LocationResponse,
responses={
400: {
"description": "总排号或货位号格式不合法",
"model": ErrorResponse,
},
409: {
"description": "重复上架或已下架",
"model": ErrorResponse,
},
},
)
def create_location(req: LocationRequest, db: Session = Depends(get_db)):
record = register_location(db, req)
return LocationResponse(
zongpai_no=record.zongpai_no,
location_code=record.location_code,
created_at=record.created_at.isoformat(),
previous_location=getattr(record, "previous_location", None),
)
@router.get(
"/location/paicha-overview",
response_model=PaichaOverviewResponse,
responses={
400: {
"description": "总排号格式不合法",
"model": ErrorResponse,
},
404: {
"description": "该总排号未找到对应排产号",
"model": ErrorResponse,
},
},
)
def paicha_overview(zongpai_no: str, db: Session = Depends(get_db)):
return get_paicha_overview(db, zongpai_no)