Initial commit: mini-erp (backend FastAPI + frontend React/Vite)
Base para el flujo de ramas por cliente. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
commit
ab3c613165
154 files changed
+16872
No files matched your search
@@ -0,0 +1,52 @@
|
||||
import base64
|
||||
from fastapi import APIRouter, HTTPException
|
||||
from fastapi.responses import StreamingResponse
|
||||
from core.api_gateway import forward_to_api_gateway
|
||||
from typing import Any, List
|
||||
from io import BytesIO
|
||||
|
||||
router = APIRouter(
|
||||
tags=["APIGateway - Crystal Reports"]
|
||||
)
|
||||
|
||||
|
||||
@router.get("/api/apigateway/reports")
|
||||
async def list_reports():
|
||||
resp = forward_to_api_gateway(
|
||||
method="GET",
|
||||
endpoint="rs/v1/LoadAuthorizedCRList"
|
||||
)
|
||||
data = resp.json()
|
||||
if isinstance(data, list):
|
||||
return data
|
||||
if isinstance(data, dict):
|
||||
return data.get("value", data.get("AuthorizedCRList", [data]))
|
||||
return []
|
||||
|
||||
|
||||
@router.get("/api/apigateway/reports/{docCode}/parameters")
|
||||
async def get_report_parameters(docCode: str):
|
||||
resp = forward_to_api_gateway(
|
||||
method="GET",
|
||||
endpoint=f"rs/v1/LoadCR",
|
||||
params={"DocCode": docCode}
|
||||
)
|
||||
return resp.json()
|
||||
|
||||
|
||||
@router.post("/api/apigateway/reports/{docCode}/export")
|
||||
async def export_report_pdf(docCode: str, body: List[Any]):
|
||||
resp = forward_to_api_gateway(
|
||||
method="POST",
|
||||
endpoint="rs/v1/ExportPDFData",
|
||||
params={"DocCode": docCode},
|
||||
json_data=body,
|
||||
)
|
||||
pdf_bytes = base64.b64decode(resp.text)
|
||||
return StreamingResponse(
|
||||
BytesIO(pdf_bytes),
|
||||
media_type="application/pdf",
|
||||
headers={
|
||||
"Content-Disposition": f'inline; filename="{docCode}.pdf"',
|
||||
}
|
||||
)
|
||||
Reference in new issue
Block a user