29 lines
1.0 KiB
Python
29 lines
1.0 KiB
Python
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 AttachmentStatusResponse, CategoryResponse
|
|
from app.services.attachment_service import 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)
|