feat(server): add attachment schemas and GET /attachment/categories
Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
22
app/api/v1/attachment.py
Normal file
22
app/api/v1/attachment.py
Normal file
@@ -0,0 +1,22 @@
|
||||
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 CategoryResponse
|
||||
|
||||
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
|
||||
]
|
||||
Reference in New Issue
Block a user