fix(09): resolve export data quality and integrate UI
This commit is contained in:
@@ -5,7 +5,7 @@ Supports CSV and Excel formats.
|
||||
|
||||
from datetime import datetime
|
||||
from fastapi import APIRouter, Depends, HTTPException, Query
|
||||
from fastapi.responses import FileResponse
|
||||
from fastapi.responses import StreamingResponse
|
||||
from sqlalchemy.orm import Session
|
||||
|
||||
from backend.database import get_db
|
||||
@@ -70,20 +70,16 @@ async def export_inventory_snapshot(
|
||||
|
||||
# Return file response
|
||||
if format_type == "csv":
|
||||
# For CSV, use FileResponse with bytes
|
||||
import io
|
||||
return FileResponse(
|
||||
return StreamingResponse(
|
||||
io.BytesIO(content.encode("utf-8")),
|
||||
media_type=media_type,
|
||||
filename=filename,
|
||||
headers={"Content-Disposition": f"attachment; filename={filename}"}
|
||||
)
|
||||
else:
|
||||
# For Excel, content is already bytes
|
||||
import io
|
||||
return FileResponse(
|
||||
return StreamingResponse(
|
||||
io.BytesIO(content),
|
||||
media_type=media_type,
|
||||
filename=filename,
|
||||
headers={"Content-Disposition": f"attachment; filename={filename}"}
|
||||
)
|
||||
|
||||
|
||||
@@ -126,22 +122,20 @@ async def export_audit_trail(
|
||||
|
||||
# Return file response
|
||||
if format_type == "csv":
|
||||
import io
|
||||
return FileResponse(
|
||||
return StreamingResponse(
|
||||
io.BytesIO(content.encode("utf-8")),
|
||||
media_type=media_type,
|
||||
filename=filename,
|
||||
headers={"Content-Disposition": f"attachment; filename={filename}"}
|
||||
)
|
||||
else:
|
||||
import io
|
||||
return FileResponse(
|
||||
return StreamingResponse(
|
||||
io.BytesIO(content),
|
||||
media_type=media_type,
|
||||
filename=filename,
|
||||
headers={"Content-Disposition": f"attachment; filename={filename}"}
|
||||
)
|
||||
|
||||
|
||||
@router.get("/db/export")
|
||||
@router.get("/reports/export")
|
||||
async def export_db(
|
||||
format: str = Query("csv", description="Export format: csv or xlsx"),
|
||||
type: str = Query("inventory", description="Export type: inventory, audit, or combined"),
|
||||
@@ -226,14 +220,14 @@ async def export_db(
|
||||
|
||||
# Return file response
|
||||
if format_type == "csv":
|
||||
return FileResponse(
|
||||
return StreamingResponse(
|
||||
io.BytesIO(content.encode("utf-8")),
|
||||
media_type=media_type,
|
||||
filename=filename,
|
||||
headers={"Content-Disposition": f"attachment; filename={filename}"}
|
||||
)
|
||||
else:
|
||||
return FileResponse(
|
||||
return StreamingResponse(
|
||||
io.BytesIO(content),
|
||||
media_type=media_type,
|
||||
filename=filename,
|
||||
headers={"Content-Disposition": f"attachment; filename={filename}"}
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user