feat(server): add attachment schemas and GET /attachment/categories

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
Misaka_Company
2026-08-12 13:37:24 +08:00
parent baa841ae42
commit ab774b8661
4 changed files with 223 additions and 0 deletions

22
app/api/v1/attachment.py Normal file
View 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
]