完善训练链路接口与PDF下载

This commit is contained in:
刘金宝
2026-06-08 15:16:07 +08:00
parent 41a2851120
commit 11b1712b01
12 changed files with 550 additions and 164 deletions
+20
View File
@@ -1,4 +1,7 @@
from pathlib import Path
from fastapi import APIRouter, Depends
from fastapi.responses import FileResponse
from sqlalchemy.orm import Session
from app.core.response import ApiResponse, ok
@@ -37,3 +40,20 @@ def export_pdf(
export = PdfExportService(db).export(evaluation_id, ctx.user_id)
db.commit()
return ok(ExportPdfResponse(export_id=export.id, file_path=export.file_path))
@router.get("/{evaluation_id}/download-pdf", response_class=FileResponse)
def download_pdf(
evaluation_id: int,
ctx: UserContext = Depends(get_user_context),
db: Session = Depends(get_db),
):
"""PDF 下载:校验评价归属后生成报告,并以文件流方式触发浏览器下载。"""
export = PdfExportService(db).export(evaluation_id, ctx.user_id)
db.commit()
file_path = Path(export.file_path)
return FileResponse(
path=file_path,
media_type="application/pdf",
filename=file_path.name,
)