api 1차 포매팅

This commit is contained in:
jaehwang committed 2026-04-20 14:41:00 +09:00
1 parent 4f42efde18
commit 9d306eb68e
18 files changed
+538 -2

No files matched your search

+7
View File
@@ -0,0 +1,7 @@
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]
+28
View File
@@ -0,0 +1,28 @@
from fastapi import APIRouter, Depends, status
from common.deps import verify_api_key
from models.analysis import AnalysisCreate, AnalysisStartResponse, AnalysisStatusResponse
router = APIRouter(prefix="/api/analyses", tags=["analyses"], dependencies=[Depends(verify_api_key)])
@router.post("", status_code=status.HTTP_202_ACCEPTED, response_model=AnalysisStartResponse)
async def start_analysis(body: AnalysisCreate):
return AnalysisStartResponse(
analysis_run_id="22222222-2222-2222-2222-222222222222",
clinic_id=body.clinic_id or "11111111-1111-1111-1111-111111111111",
status="discovering",
estimated_seconds=90,
poll_url="/api/analyses/22222222-2222-2222-2222-222222222222/status",
)
@router.get("/{run_id}/status", response_model=AnalysisStatusResponse)
async def get_analysis_status(run_id: str):
return AnalysisStatusResponse(
analysis_run_id=run_id,
status="collecting",
progress=0.45,
current_step="채널 데이터 수집 중",
channel_errors={},
completed_at=None,
)
+21
View File
@@ -0,0 +1,21 @@
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)])
@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,
)
+34
View File
@@ -0,0 +1,34 @@
from fastapi import APIRouter, Depends, status
from common.deps import verify_api_key
from models.clinic import ClinicCreate, ClinicCreateResponse, ClinicHistoryResponse, RunSummary
router = APIRouter(prefix="/api/clinics", tags=["clinics"], dependencies=[Depends(verify_api_key)])
@router.post("", status_code=status.HTTP_201_CREATED, response_model=ClinicCreateResponse)
async def create_clinic(body: ClinicCreate):
return ClinicCreateResponse(
id="11111111-1111-1111-1111-111111111111",
url=body.url,
name=body.name,
created_at="2026-04-20T09:00:00Z",
)
@router.get("/{id}/history", response_model=ClinicHistoryResponse)
async def get_clinic_history(id: str):
return ClinicHistoryResponse(
clinic_id=id,
runs=[
RunSummary(
run_id="22222222-2222-2222-2222-222222222222",
status="complete",
started_at="2026-04-20T09:00:00Z",
completed_at="2026-04-20T09:01:30Z",
overall_score=82,
)
],
metrics_timeseries={
"youtube_subscribers": [{"date": "2026-04-20", "value": 12345}]
},
)
+31
View File
@@ -0,0 +1,31 @@
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)])
@router.post("", status_code=status.HTTP_201_CREATED, response_model=PlanResponse)
async def create_plan(body: PlanCreate):
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):
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",
)
+24
View File
@@ -0,0 +1,24 @@
from fastapi import APIRouter, Depends
from common.deps import verify_api_key
from models.report import ReportResponse, ClinicInfo
router = APIRouter(prefix="/api/reports", tags=["reports"], dependencies=[Depends(verify_api_key)])
@router.get("/{run_id}", response_model=ReportResponse)
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",
)
View File
Whitespace-only changes.
+6
View File
@@ -0,0 +1,6 @@
import os
from fastapi import Header, HTTPException
async def verify_api_key(x_api_key: str = Header(...)):
if x_api_key != os.getenv("API_KEY"):
raise HTTPException(status_code=401, detail="Invalid API Key")
+7
View File
@@ -1,7 +1,14 @@
from fastapi import FastAPI
from dotenv import load_dotenv
from api import routers
load_dotenv()
app = FastAPI()
for router in routers:
app.include_router(router)
@app.get("/health")
def health():
View File
Whitespace-only changes.
+38
View File
@@ -0,0 +1,38 @@
from pydantic import BaseModel
class Channels(BaseModel):
youtube: str | None = None
instagram: list[str] | str | None = None
facebook: str | None = None
naver_blog: str | None = None
gangnam_unni: str | None = None
class AnalysisOptions(BaseModel):
skip_vision: bool = False
skip_perplexity: bool = False
class AnalysisCreate(BaseModel):
clinic_id: str | None = None
url: str | None = None
channels: Channels
options: AnalysisOptions = AnalysisOptions()
class AnalysisStartResponse(BaseModel):
analysis_run_id: str
clinic_id: str
status: str
estimated_seconds: int
poll_url: str
class AnalysisStatusResponse(BaseModel):
analysis_run_id: str
status: str
progress: float
current_step: str
channel_errors: dict
completed_at: str | None
+12
View File
@@ -0,0 +1,12 @@
from pydantic import BaseModel
from typing import Any
class ChannelVerifyRequest(BaseModel):
youtube: str | None = None
instagram: list[str] | None = None
class ChannelVerifyResponse(BaseModel):
youtube: dict[str, Any] | None = None
instagram: list[dict[str, Any]] | None = None
+29
View File
@@ -0,0 +1,29 @@
from pydantic import BaseModel
class ClinicCreate(BaseModel):
url: str
name: str
name_en: str | None = None
address: str | None = None
class ClinicCreateResponse(BaseModel):
id: str
url: str
name: str
created_at: str
class RunSummary(BaseModel):
run_id: str
status: str
started_at: str
completed_at: str | None
overall_score: int | None
class ClinicHistoryResponse(BaseModel):
clinic_id: str
runs: list[RunSummary]
metrics_timeseries: dict
+16
View File
@@ -0,0 +1,16 @@
from pydantic import BaseModel
class PlanCreate(BaseModel):
report_id: str
regenerate: bool = False
class PlanResponse(BaseModel):
id: str
analysis_run_id: str
brand_guide: dict
channel_strategies: list
content_strategy: dict
calendar: list
created_at: str
+22
View File
@@ -0,0 +1,22 @@
from pydantic import BaseModel
class ClinicInfo(BaseModel):
name: str
url: str
class ReportResponse(BaseModel):
id: str
clinic: ClinicInfo
overall_score: int
youtube: dict
instagram: dict
facebook: dict
naver_place: dict
naver_blog: dict
gangnam_unni: dict
conversion_strategy: dict
roadmap: list
kpis: list
generated_at: str