31 lines
1.0 KiB
Python
31 lines
1.0 KiB
Python
from fastapi import APIRouter, Depends, HTTPException, Query, status
|
|
from sqlalchemy.orm import Session
|
|
|
|
from app.core.deps import require_staff
|
|
from app.db import get_db
|
|
from app.models.uploaded_case import list_uploaded_cases, uploaded_case_detail
|
|
|
|
router = APIRouter(dependencies=[Depends(require_staff)])
|
|
|
|
|
|
@router.get("/uploaded-cases")
|
|
def read_uploaded_cases(
|
|
kind: str = Query("residential"),
|
|
current: int = Query(1),
|
|
size: int = Query(10),
|
|
q: str = Query(""),
|
|
db: Session = Depends(get_db),
|
|
) -> dict:
|
|
body = list_uploaded_cases(db, kind=kind, current=current, size=size, q=q)
|
|
if body is None:
|
|
raise HTTPException(status_code=status.HTTP_404_NOT_FOUND, detail="案例种类不正确")
|
|
return body
|
|
|
|
|
|
@router.get("/uploaded-cases/{case_id}")
|
|
def read_uploaded_case(case_id: int, db: Session = Depends(get_db)) -> dict:
|
|
body = uploaded_case_detail(db, case_id)
|
|
if body is None:
|
|
raise HTTPException(status_code=status.HTTP_404_NOT_FOUND, detail="上传案例不存在")
|
|
return body
|