- 4개 검사 엔진: HTML/CSS, 접근성(WCAG), SEO, 성능/보안 (총 50개 항목) - FastAPI 백엔드 (9개 API, SSE 실시간 진행, PDF/JSON 리포트) - Next.js 15 프론트엔드 (6개 페이지, 29개 컴포넌트, 반원 게이지 차트) - Docker Compose 배포 (Backend:8011, Frontend:3011, MongoDB:27022, Redis:6392) - 전체 테스트 32/32 PASS Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
82 lines
2.2 KiB
Python
82 lines
2.2 KiB
Python
"""
|
|
Reports router.
|
|
Handles PDF and JSON report download.
|
|
"""
|
|
|
|
import logging
|
|
|
|
from fastapi import APIRouter, HTTPException
|
|
from fastapi.responses import Response
|
|
|
|
from app.core.database import get_db
|
|
from app.core.redis import get_redis
|
|
from app.services.inspection_service import InspectionService
|
|
from app.services.report_service import ReportService
|
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
router = APIRouter()
|
|
report_service = ReportService()
|
|
|
|
|
|
def _get_inspection_service() -> InspectionService:
|
|
"""Get InspectionService instance."""
|
|
db = get_db()
|
|
redis = get_redis()
|
|
return InspectionService(db=db, redis=redis)
|
|
|
|
|
|
@router.get("/inspections/{inspection_id}/report/pdf")
|
|
async def download_pdf(inspection_id: str):
|
|
"""Download inspection report as PDF."""
|
|
service = _get_inspection_service()
|
|
inspection = await service.get_inspection(inspection_id)
|
|
|
|
if inspection is None:
|
|
raise HTTPException(
|
|
status_code=404,
|
|
detail="검사 결과를 찾을 수 없습니다",
|
|
)
|
|
|
|
try:
|
|
pdf_bytes = await report_service.generate_pdf(inspection)
|
|
except RuntimeError as e:
|
|
raise HTTPException(
|
|
status_code=500,
|
|
detail=str(e),
|
|
)
|
|
|
|
filename = report_service.generate_filename(inspection.get("url", "unknown"), "pdf")
|
|
|
|
return Response(
|
|
content=pdf_bytes,
|
|
media_type="application/pdf",
|
|
headers={
|
|
"Content-Disposition": f'attachment; filename="{filename}"',
|
|
},
|
|
)
|
|
|
|
|
|
@router.get("/inspections/{inspection_id}/report/json")
|
|
async def download_json(inspection_id: str):
|
|
"""Download inspection report as JSON file."""
|
|
service = _get_inspection_service()
|
|
inspection = await service.get_inspection(inspection_id)
|
|
|
|
if inspection is None:
|
|
raise HTTPException(
|
|
status_code=404,
|
|
detail="검사 결과를 찾을 수 없습니다",
|
|
)
|
|
|
|
json_bytes = await report_service.generate_json(inspection)
|
|
filename = report_service.generate_filename(inspection.get("url", "unknown"), "json")
|
|
|
|
return Response(
|
|
content=json_bytes,
|
|
media_type="application/json",
|
|
headers={
|
|
"Content-Disposition": f'attachment; filename="{filename}"',
|
|
},
|
|
)
|