Initial commit: Data Analysis application with FastAPI backend and Next.js frontend
This commit is contained in:
33
backend/app/api/v1/reports.py
Normal file
33
backend/app/api/v1/reports.py
Normal file
@@ -0,0 +1,33 @@
|
||||
from fastapi import APIRouter, HTTPException, Response
|
||||
from pydantic import BaseModel
|
||||
from typing import Dict, Any, List
|
||||
from app.core.engine.reports import create_pdf_report
|
||||
|
||||
router = APIRouter(prefix="/reports", tags=["reporting"])
|
||||
|
||||
class ExportRequest(BaseModel):
|
||||
project_name: str
|
||||
results: Dict[str, Any]
|
||||
audit_trail: Dict[str, Any]
|
||||
|
||||
@router.post("/export")
|
||||
async def export_report(request: ExportRequest):
|
||||
"""
|
||||
Generates and returns a PDF report.
|
||||
"""
|
||||
try:
|
||||
pdf_bytes = create_pdf_report(
|
||||
request.project_name,
|
||||
request.results,
|
||||
request.audit_trail
|
||||
)
|
||||
|
||||
return Response(
|
||||
content=pdf_bytes,
|
||||
media_type="application/pdf",
|
||||
headers={
|
||||
"Content-Disposition": f"attachment; filename=Report_{request.project_name}.pdf"
|
||||
}
|
||||
)
|
||||
except Exception as e:
|
||||
raise HTTPException(status_code=500, detail=str(e))
|
||||
Reference in New Issue
Block a user