report output format 변경 및 clinic info출력 추가
This commit is contained in:
1 parent
c1f39aceff
commit
9b4e99abf9
7 files changed
+689
-55
No files matched your search
+18
-3
@@ -4,18 +4,33 @@ from fastapi import APIRouter, Depends, HTTPException, Response
|
||||
from common.db import fetchone
|
||||
from common.deps import verify_api_key
|
||||
from integrations.llm.schemas.plan import PlanOutput
|
||||
from models.plan import PlanApiResponse
|
||||
|
||||
router = APIRouter(prefix="/api/plans", tags=["plans"], dependencies=[Depends(verify_api_key)])
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
@router.get("/{run_id}", response_model=PlanOutput | None)
|
||||
@router.get("/{run_id}", response_model=PlanApiResponse)
|
||||
async def get_plan(run_id: str):
|
||||
logger.info("GET /api/plans/%s", run_id)
|
||||
row = await fetchone("SELECT plan_data FROM analysis_runs WHERE analysis_run_id = %s", (run_id,))
|
||||
row = await fetchone(
|
||||
"SELECT ar.plan_data, ar.created_at, h.hospital_name, h.hospital_name_en, h.url"
|
||||
" FROM analysis_runs ar"
|
||||
" JOIN hospital_baseinfo h ON ar.hospital_id = h.hospital_id"
|
||||
" WHERE ar.analysis_run_id = %s",
|
||||
(run_id,),
|
||||
)
|
||||
if row is None:
|
||||
raise HTTPException(status_code=404, detail="Run not found")
|
||||
if row["plan_data"] is None:
|
||||
return Response(status_code=204)
|
||||
data = json.loads(row["plan_data"]) if isinstance(row["plan_data"], str) else row["plan_data"]
|
||||
return PlanOutput(**data)
|
||||
plan = PlanOutput(**data)
|
||||
return PlanApiResponse(
|
||||
id=run_id,
|
||||
clinicName=row["hospital_name"],
|
||||
clinicNameEn=row["hospital_name_en"],
|
||||
createdAt=str(row["created_at"]),
|
||||
targetUrl=row["url"],
|
||||
**plan.model_dump(),
|
||||
)
|
||||
+14
-3
@@ -4,16 +4,20 @@ from fastapi import APIRouter, Depends, HTTPException, Response
|
||||
from common.db import fetchone
|
||||
from common.deps import verify_api_key
|
||||
from integrations.llm.schemas.report import ReportOutput
|
||||
from models.report import MarketingReportResponse
|
||||
|
||||
router = APIRouter(prefix="/api/reports", tags=["reports"], dependencies=[Depends(verify_api_key)])
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
@router.get("/{run_id}", response_model=ReportOutput | None)
|
||||
@router.get("/{run_id}", response_model=MarketingReportResponse, response_model_by_alias=True)
|
||||
async def get_report(run_id: str):
|
||||
logger.info("GET /api/reports/%s", run_id)
|
||||
row = await fetchone(
|
||||
"SELECT report_data FROM analysis_runs WHERE analysis_run_id = %s",
|
||||
"SELECT ar.report_data, ar.created_at, h.hospital_name, h.hospital_name_en, h.url"
|
||||
" FROM analysis_runs ar"
|
||||
" JOIN hospital_baseinfo h ON ar.hospital_id = h.hospital_id"
|
||||
" WHERE ar.analysis_run_id = %s",
|
||||
(run_id,),
|
||||
)
|
||||
if row is None:
|
||||
@@ -21,4 +25,11 @@ async def get_report(run_id: str):
|
||||
if row["report_data"] is None:
|
||||
return Response(status_code=204)
|
||||
data = json.loads(row["report_data"]) if isinstance(row["report_data"], str) else row["report_data"]
|
||||
return ReportOutput(**data)
|
||||
llm_output = ReportOutput(**data)
|
||||
response = MarketingReportResponse.model_validate(llm_output.model_dump())
|
||||
response.id = run_id
|
||||
response.clinic_name = row["hospital_name"]
|
||||
response.clinic_name_en = row["hospital_name_en"]
|
||||
response.created_at = str(row["created_at"])
|
||||
response.target_url = row["url"]
|
||||
return response
|
||||
Reference in new issue
Block a user