llm 붙임 및 리포트 생성 확인
This commit is contained in:
1 parent
26cd946e1b
commit
2b8a90e857
26 files changed
+507
-175
No files matched your search
+1
-2
@@ -2,6 +2,5 @@ from .clinics import router as clinics_router
|
||||
from .analyses import router as analyses_router
|
||||
from .reports import router as reports_router
|
||||
from .plans import router as plans_router
|
||||
from .channels import router as channels_router
|
||||
|
||||
routers = [clinics_router, analyses_router, reports_router, plans_router, channels_router]
|
||||
routers = [clinics_router, analyses_router, reports_router, plans_router]
|
||||
+9
-4
@@ -1,3 +1,4 @@
|
||||
import logging
|
||||
import uuid6
|
||||
from fastapi import APIRouter, BackgroundTasks, Depends, status, HTTPException
|
||||
from common.deps import verify_api_key
|
||||
@@ -7,10 +8,12 @@ from models.status import AnalysisStatus
|
||||
from services.collect import collect_instagram, collect_facebook, collect_naver_blog, collect_youtube, collect_gangnam_unni
|
||||
|
||||
router = APIRouter(prefix="/api/analyses", tags=["analyses"], dependencies=[Depends(verify_api_key)])
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
@router.post("", status_code=status.HTTP_202_ACCEPTED, response_model=AnalysisStartResponse)
|
||||
async def start_analysis(body: AnalysisCreate, background_tasks: BackgroundTasks):
|
||||
logger.info("POST /api/analyses clinic_id=%s", body.clinic_id)
|
||||
analysis_run_id = str(uuid6.uuid7())
|
||||
hospital_id = body.clinic_id
|
||||
|
||||
@@ -23,8 +26,7 @@ async def start_analysis(body: AnalysisCreate, background_tasks: BackgroundTasks
|
||||
raise HTTPException(status_code=409, detail="Clinic not found")
|
||||
owner_user_id = hospital["owner_user_id"] if hospital else 0
|
||||
|
||||
ig_url = body.channels.instagram[0] if isinstance(body.channels.instagram, list) else body.channels.instagram
|
||||
ig_id = await insert_instagram_row(hospital_id, ig_url) if ig_url else None
|
||||
ig_id = await insert_instagram_row(hospital_id, body.channels.instagram) if body.channels.instagram else None
|
||||
fb_id = await insert_facebook_row(hospital_id, body.channels.facebook) if body.channels.facebook else None
|
||||
nb_id = await insert_naver_blog_row(hospital_id, body.channels.naver_blog) if body.channels.naver_blog else None
|
||||
yt_id = await insert_youtube_row(hospital_id, body.channels.youtube) if body.channels.youtube else None
|
||||
@@ -33,9 +35,9 @@ async def start_analysis(body: AnalysisCreate, background_tasks: BackgroundTasks
|
||||
analysis_run_id = await insert_analysis_run(analysis_run_id, hospital_id, owner_user_id, ig_id, fb_id, nb_id, yt_id, gu_id)
|
||||
|
||||
if ig_id:
|
||||
background_tasks.add_task(collect_instagram, analysis_run_id, ig_id, ig_url)
|
||||
background_tasks.add_task(collect_instagram, analysis_run_id, ig_id, body.channels.instagram)
|
||||
if fb_id:
|
||||
background_tasks.add_task(collect_facebook, analysis_run_id, fb_id, f"https://www.facebook.com/{body.channels.facebook}")
|
||||
background_tasks.add_task(collect_facebook, analysis_run_id, fb_id, body.channels.facebook)
|
||||
if nb_id:
|
||||
background_tasks.add_task(collect_naver_blog, analysis_run_id, nb_id, body.channels.naver_blog)
|
||||
if yt_id:
|
||||
@@ -54,7 +56,10 @@ async def start_analysis(body: AnalysisCreate, background_tasks: BackgroundTasks
|
||||
|
||||
@router.get("/{run_id}/status", response_model=AnalysisStatusResponse)
|
||||
async def get_analysis_status(run_id: str):
|
||||
logger.info("GET /api/analyses/%s/status", run_id)
|
||||
row = await fetchone("SELECT status FROM analysis_runs WHERE analysis_run_id = %s", (run_id,))
|
||||
if not row:
|
||||
raise HTTPException(status_code=404, detail="Run not found")
|
||||
return AnalysisStatusResponse(
|
||||
analysis_run_id=run_id,
|
||||
status=AnalysisStatus(row["status"]),
|
||||
|
||||
@@ -1,23 +0,0 @@
|
||||
from fastapi import APIRouter, Depends
|
||||
from common.deps import verify_api_key
|
||||
from models.channel import ChannelVerifyRequest, ChannelVerifyResponse
|
||||
|
||||
router = APIRouter(prefix="/api/channels", tags=["channels"], dependencies=[Depends(verify_api_key)])
|
||||
|
||||
|
||||
# will not use
|
||||
|
||||
@router.post("/verify", response_model=ChannelVerifyResponse)
|
||||
async def verify_channels(body: ChannelVerifyRequest):
|
||||
return ChannelVerifyResponse(
|
||||
youtube={
|
||||
"handle": body.youtube,
|
||||
"verified": True,
|
||||
"display_name": "바노바기 BANOBAGI",
|
||||
"followers": 12345,
|
||||
} if body.youtube else None,
|
||||
instagram=[
|
||||
{"handle": handle, "verified": "unverifiable", "note": "Instagram 로그인 벽"}
|
||||
for handle in body.instagram
|
||||
] if body.instagram else None,
|
||||
)
|
||||
+41
-5
@@ -1,28 +1,64 @@
|
||||
import logging
|
||||
import uuid6
|
||||
from fastapi import APIRouter, Depends, status
|
||||
from fastapi import APIRouter, Depends, HTTPException, status
|
||||
from common.deps import verify_api_key
|
||||
from common.db import insert_hospital
|
||||
from models.clinic import ClinicCreate, ClinicCreateResponse, ClinicHistoryResponse, RunSummary
|
||||
from common.db import insert_hospital, fetchone
|
||||
from common.utils import get_env
|
||||
from integrations.firecrawl import FirecrawlClient
|
||||
from models.clinic import ClinicCreate, ClinicCreateResponse, ClinicResponse, ClinicHistoryResponse, RunSummary
|
||||
|
||||
router = APIRouter(prefix="/api/clinics", tags=["clinics"], dependencies=[Depends(verify_api_key)])
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
_REQUIRED_FIELDS = ["clinicName"]
|
||||
_COLLECTED_FIELDS = ["clinicName", "clinicNameEn", "address", "phone", "slogan", "services", "doctors"]
|
||||
|
||||
|
||||
@router.post("", status_code=status.HTTP_201_CREATED, response_model=ClinicCreateResponse)
|
||||
async def create_clinic(body: ClinicCreate):
|
||||
logger.info("POST /api/clinics url=%s", body.url)
|
||||
info = await FirecrawlClient(get_env("FIRECRAWL_API_KEY")).fetch_clinic_info(body.url)
|
||||
|
||||
missing = [f for f in _COLLECTED_FIELDS if not (info or {}).get(f)]
|
||||
required_missing = [f for f in _REQUIRED_FIELDS if f in missing]
|
||||
if required_missing:
|
||||
raise HTTPException(status_code=404, detail={"missing": missing})
|
||||
|
||||
hospital_id = str(uuid6.uuid7())
|
||||
row = await insert_hospital(hospital_id, body.name, body.name_en, body.address, body.url)
|
||||
row = await insert_hospital(
|
||||
hospital_id,
|
||||
name=info["clinicName"],
|
||||
name_en=info.get("clinicNameEn"),
|
||||
road_address=info.get("address"),
|
||||
url=body.url,
|
||||
raw_data=info,
|
||||
)
|
||||
return ClinicCreateResponse(
|
||||
id=hospital_id,
|
||||
url=body.url,
|
||||
name=body.name,
|
||||
name=info["clinicName"],
|
||||
created_at=str(row["created_at"]),
|
||||
)
|
||||
|
||||
|
||||
@router.get("/{hospital_id}", response_model=ClinicResponse)
|
||||
async def get_clinic(hospital_id: str):
|
||||
logger.info("GET /api/clinics/%s", hospital_id)
|
||||
row = await fetchone(
|
||||
"SELECT hospital_id, hospital_name, hospital_name_en, road_address, url, status, raw_data, created_at, updated_at"
|
||||
" FROM hospital_baseinfo WHERE hospital_id = %s",
|
||||
(hospital_id,),
|
||||
)
|
||||
if not row:
|
||||
raise HTTPException(status_code=404, detail="Clinic not found")
|
||||
return ClinicResponse(**{**row, "created_at": str(row["created_at"]), "updated_at": str(row["updated_at"])})
|
||||
|
||||
|
||||
# Not done
|
||||
|
||||
@router.get("/{id}/history", response_model=ClinicHistoryResponse)
|
||||
async def get_clinic_history(id: str):
|
||||
logger.info("GET /api/clinics/%s/history", id)
|
||||
return ClinicHistoryResponse(
|
||||
clinic_id=id,
|
||||
runs=[
|
||||
|
||||
@@ -1,12 +1,15 @@
|
||||
import logging
|
||||
from fastapi import APIRouter, Depends, status
|
||||
from common.deps import verify_api_key
|
||||
from models.plan import PlanCreate, PlanResponse
|
||||
|
||||
router = APIRouter(prefix="/api/plans", tags=["plans"], dependencies=[Depends(verify_api_key)])
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
@router.post("", status_code=status.HTTP_201_CREATED, response_model=PlanResponse)
|
||||
async def create_plan(body: PlanCreate):
|
||||
logger.info("POST /api/plans run_id=%s", body.analysis_run_id)
|
||||
return PlanResponse(
|
||||
id="33333333-3333-3333-3333-333333333333",
|
||||
analysis_run_id="22222222-2222-2222-2222-222222222222",
|
||||
@@ -20,6 +23,7 @@ async def create_plan(body: PlanCreate):
|
||||
|
||||
@router.get("/{id}", response_model=PlanResponse)
|
||||
async def get_plan(id: str):
|
||||
logger.info("GET /api/plans/%s", id)
|
||||
return PlanResponse(
|
||||
id=id,
|
||||
analysis_run_id="22222222-2222-2222-2222-222222222222",
|
||||
|
||||
+17
-17
@@ -1,24 +1,24 @@
|
||||
from fastapi import APIRouter, Depends
|
||||
import json
|
||||
import logging
|
||||
from fastapi import APIRouter, Depends, HTTPException, Response
|
||||
from common.db import fetchone
|
||||
from common.deps import verify_api_key
|
||||
from models.report import ReportResponse, ClinicInfo
|
||||
from integrations.llm.schemas.report import ReportOutput
|
||||
|
||||
router = APIRouter(prefix="/api/reports", tags=["reports"], dependencies=[Depends(verify_api_key)])
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
@router.get("/{run_id}", response_model=ReportResponse)
|
||||
@router.get("/{run_id}", response_model=ReportOutput | None)
|
||||
async def get_report(run_id: str):
|
||||
return ReportResponse(
|
||||
id=run_id,
|
||||
clinic=ClinicInfo(name="바노바기성형외과", url="https://www.banobagi.com"),
|
||||
overall_score=82,
|
||||
youtube={},
|
||||
instagram={},
|
||||
facebook={},
|
||||
naver_place={},
|
||||
naver_blog={},
|
||||
gangnam_unni={},
|
||||
conversion_strategy={},
|
||||
roadmap=[],
|
||||
kpis=[],
|
||||
generated_at="2026-04-20T09:01:30Z",
|
||||
logger.info("GET /api/reports/%s", run_id)
|
||||
row = await fetchone(
|
||||
"SELECT report_data FROM analysis_runs WHERE analysis_run_id = %s",
|
||||
(run_id,),
|
||||
)
|
||||
if row is None:
|
||||
raise HTTPException(status_code=404, detail="Run not found")
|
||||
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)
|
||||
Reference in new issue
Block a user