plan 추가, analysis 오탈자 제거
This commit is contained in:
1 parent
eec682b02c
commit
602c69543c
11 files changed
+440
-43
No files matched your search
+2
-2
@@ -1,6 +1,6 @@
|
||||
from .clinics import router as clinics_router
|
||||
from .analyses import router as analyses_router
|
||||
from .analysis import router as analysis_router
|
||||
from .reports import router as reports_router
|
||||
from .plans import router as plans_router
|
||||
|
||||
routers = [clinics_router, analyses_router, reports_router, plans_router]
|
||||
routers = [clinics_router, analysis_router, reports_router, plans_router]
|
||||
@@ -5,21 +5,21 @@ from common.deps import verify_api_key
|
||||
from common.db import fetchone, insert_instagram_row, insert_facebook_row, insert_naver_blog_row, insert_youtube_row, insert_gangnam_unni_row, insert_analysis_run
|
||||
from models.analysis import AnalysisCreate, AnalysisStartResponse, AnalysisStatusResponse
|
||||
from models.status import AnalysisStatus
|
||||
from services.collect import collect_instagram, collect_facebook, collect_naver_blog, collect_youtube, collect_gangnam_unni
|
||||
from services.collect import collect_instagram, collect_facebook, collect_naver_blog, collect_youtube, collect_gangnam_unni, collect_clinic_info
|
||||
|
||||
router = APIRouter(prefix="/api/analyses", tags=["analyses"], dependencies=[Depends(verify_api_key)])
|
||||
router = APIRouter(prefix="/api/analysis", tags=["analysis"], 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)
|
||||
logger.info("POST /api/analysis clinic_id=%s", body.clinic_id)
|
||||
analysis_run_id = str(uuid6.uuid7())
|
||||
hospital_id = body.clinic_id
|
||||
|
||||
# 사실 hospital과 owner_user_id 비교 후 검증이 필요한 거지만 일단 PoC 니까. 나중에 바꿉니다.
|
||||
hospital = await fetchone(
|
||||
"SELECT owner_user_id FROM hospital_baseinfo WHERE hospital_id = %s",
|
||||
"SELECT owner_user_id, url FROM hospital_baseinfo WHERE hospital_id = %s",
|
||||
(hospital_id,),
|
||||
)
|
||||
if not hospital:
|
||||
@@ -34,6 +34,8 @@ 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)
|
||||
|
||||
background_tasks.add_task(collect_clinic_info, analysis_run_id, hospital_id, hospital["url"])
|
||||
|
||||
if ig_id:
|
||||
background_tasks.add_task(collect_instagram, analysis_run_id, ig_id, body.channels.instagram)
|
||||
if fb_id:
|
||||
@@ -50,13 +52,13 @@ async def start_analysis(body: AnalysisCreate, background_tasks: BackgroundTasks
|
||||
clinic_id=hospital_id,
|
||||
status=AnalysisStatus.DISCOVERING,
|
||||
estimated_seconds=90,
|
||||
poll_url=f"/api/analyses/{analysis_run_id}/status",
|
||||
poll_url=f"/api/analysis/{analysis_run_id}/status",
|
||||
)
|
||||
|
||||
|
||||
@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)
|
||||
logger.info("GET /api/analysis/%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")
|
||||
+14
-28
@@ -1,35 +1,21 @@
|
||||
import json
|
||||
import logging
|
||||
from fastapi import APIRouter, Depends, status
|
||||
from fastapi import APIRouter, Depends, HTTPException, Response
|
||||
from common.db import fetchone
|
||||
from common.deps import verify_api_key
|
||||
from models.plan import PlanCreate, PlanResponse
|
||||
from integrations.llm.schemas.plan import PlanOutput
|
||||
|
||||
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",
|
||||
brand_guide={},
|
||||
channel_strategies=[],
|
||||
content_strategy={},
|
||||
calendar=[],
|
||||
created_at="2026-04-20T09:10:00Z",
|
||||
)
|
||||
|
||||
|
||||
@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",
|
||||
brand_guide={},
|
||||
channel_strategies=[],
|
||||
content_strategy={},
|
||||
calendar=[],
|
||||
created_at="2026-04-20T09:10:00Z",
|
||||
)
|
||||
@router.get("/{run_id}", response_model=PlanOutput | None)
|
||||
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,))
|
||||
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)
|
||||
Reference in new issue
Block a user