feat(server): add PUT /attachment/config with removal guard
Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
55
app/main.py
55
app/main.py
@@ -32,6 +32,12 @@ from app.services.box_service import (
|
||||
InvalidZongpaiError,
|
||||
ZongpaiNotFoundError,
|
||||
)
|
||||
from app.services.attachment_service import (
|
||||
AlreadyOffShelfAttachmentError,
|
||||
CategoryHasBoxesError,
|
||||
CategoryNotFoundError,
|
||||
DuplicateAttachmentLocationError,
|
||||
)
|
||||
|
||||
app = FastAPI(title="CargoTrace API", version="0.1.0")
|
||||
|
||||
@@ -176,6 +182,55 @@ async def invalid_box_item_handler(request: Request, exc: InvalidBoxItemError):
|
||||
)
|
||||
|
||||
|
||||
@app.exception_handler(CategoryNotFoundError)
|
||||
async def category_not_found_handler(request: Request, exc: CategoryNotFoundError):
|
||||
return JSONResponse(
|
||||
status_code=404,
|
||||
content={"error_code": "CATEGORY_NOT_FOUND", "message": "附件类型不存在"},
|
||||
)
|
||||
|
||||
|
||||
@app.exception_handler(CategoryHasBoxesError)
|
||||
async def category_has_boxes_handler(request: Request, exc: CategoryHasBoxesError):
|
||||
return JSONResponse(
|
||||
status_code=409,
|
||||
content={
|
||||
"error_code": "CATEGORY_HAS_BOXES",
|
||||
"message": f"类型 {exc.category_name} 已有装箱记录,不可删除,可改应到数量",
|
||||
},
|
||||
)
|
||||
|
||||
|
||||
@app.exception_handler(DuplicateAttachmentLocationError)
|
||||
async def duplicate_attachment_location_handler(
|
||||
request: Request, exc: DuplicateAttachmentLocationError
|
||||
):
|
||||
return JSONResponse(
|
||||
status_code=409,
|
||||
content={
|
||||
"error_code": "DUPLICATE_LOCATION",
|
||||
"message": "该总排号该类型已存在货位记录",
|
||||
"location_code": exc.location_code,
|
||||
"registered_at": exc.registered_at,
|
||||
},
|
||||
)
|
||||
|
||||
|
||||
@app.exception_handler(AlreadyOffShelfAttachmentError)
|
||||
async def already_off_shelf_attachment_handler(
|
||||
request: Request, exc: AlreadyOffShelfAttachmentError
|
||||
):
|
||||
return JSONResponse(
|
||||
status_code=409,
|
||||
content={
|
||||
"error_code": "ALREADY_OFF_SHELF",
|
||||
"message": "该总排号该类型已下架至转运区域,不可重新上架",
|
||||
"location_code": exc.location_code,
|
||||
"registered_at": exc.registered_at,
|
||||
},
|
||||
)
|
||||
|
||||
|
||||
@app.get("/")
|
||||
async def root():
|
||||
return {"message": "Welcome to CargoTrace API"}
|
||||
|
||||
Reference in New Issue
Block a user