dev
This commit is contained in:
29
domain-api/app/api/routes/exports.py
Normal file
29
domain-api/app/api/routes/exports.py
Normal file
@@ -0,0 +1,29 @@
|
||||
from pathlib import Path
|
||||
|
||||
from fastapi import APIRouter, HTTPException
|
||||
from fastapi.responses import FileResponse
|
||||
|
||||
from app.schemas.common import ApiResponse
|
||||
from app.services.export_service import create_export_file, list_exports
|
||||
from app.core.files import exports_root
|
||||
|
||||
router = APIRouter(tags=["exports"])
|
||||
|
||||
|
||||
@router.get("/exports", response_model=ApiResponse)
|
||||
def export_list() -> ApiResponse:
|
||||
return ApiResponse(data=list_exports())
|
||||
|
||||
|
||||
@router.post("/exports/run", response_model=ApiResponse)
|
||||
def export_run(payload: dict) -> ApiResponse:
|
||||
record = create_export_file(payload)
|
||||
return ApiResponse(message="导出文件已生成", data=record)
|
||||
|
||||
|
||||
@router.get("/exports/download/{filename}")
|
||||
def export_download(filename: str):
|
||||
path = exports_root() / Path(filename).name
|
||||
if not path.exists():
|
||||
raise HTTPException(status_code=404, detail="文件不存在")
|
||||
return FileResponse(path, filename=path.name)
|
||||
Reference in New Issue
Block a user