from fastapi import APIRouter, Depends from sqlalchemy.orm import Session from app.core.database import get_db from app.models.attachment import AttachmentCategory from app.schemas.attachment import ( AttachmentConfigRequest, AttachmentStatusResponse, CategoryResponse, ) from app.services.attachment_service import ( configure_attachment, get_attachment_status, ) router = APIRouter(tags=["attachment"]) @router.get("/attachment/categories", response_model=list[CategoryResponse]) def list_categories(db: Session = Depends(get_db)): """列出启用中的附件类型,按 sort_order、name 排序。""" rows = ( db.query(AttachmentCategory) .filter(AttachmentCategory.is_active == True) .order_by(AttachmentCategory.sort_order, AttachmentCategory.name) .all() ) return [ CategoryResponse(id=r.id, name=r.name, sort_order=r.sort_order) for r in rows ] @router.get("/attachment/status", response_model=AttachmentStatusResponse) def attachment_status(zongpai_no: str, db: Session = Depends(get_db)): return get_attachment_status(db, zongpai_no) @router.put("/attachment/config", response_model=AttachmentStatusResponse) def put_attachment_config(req: AttachmentConfigRequest, db: Session = Depends(get_db)): return configure_attachment(db, req)