71 lines
2.1 KiB
Python
71 lines
2.1 KiB
Python
"""Tarot Lab 엔드포인트 — interpret + readings CRUD."""
|
|
from fastapi import APIRouter, HTTPException
|
|
|
|
from ..models import (
|
|
TarotInterpretRequest,
|
|
TarotInterpretResponse,
|
|
TarotSaveRequest,
|
|
TarotPatchRequest,
|
|
)
|
|
from ..tarot import pipeline
|
|
from .. import db as db_module
|
|
|
|
|
|
router = APIRouter(prefix="/api/agent-office/tarot")
|
|
|
|
|
|
@router.post("/interpret", response_model=TarotInterpretResponse)
|
|
async def interpret_endpoint(req: TarotInterpretRequest):
|
|
try:
|
|
result = await pipeline.interpret(req)
|
|
except pipeline.TarotError as e:
|
|
raise HTTPException(status_code=500, detail=str(e)) from e
|
|
return result
|
|
|
|
|
|
@router.post("/readings")
|
|
async def save_reading(req: TarotSaveRequest):
|
|
rid = db_module.save_tarot_reading(req.model_dump())
|
|
row = db_module.get_tarot_reading(rid)
|
|
return {"id": rid, "created_at": row["created_at"]}
|
|
|
|
|
|
@router.get("/readings")
|
|
async def list_readings(
|
|
page: int = 1,
|
|
size: int = 20,
|
|
favorite: bool | None = None,
|
|
spread_type: str | None = None,
|
|
category: str | None = None,
|
|
):
|
|
return db_module.list_tarot_readings(
|
|
page=page, size=size,
|
|
favorite=favorite, spread_type=spread_type, category=category,
|
|
)
|
|
|
|
|
|
@router.get("/readings/{reading_id}")
|
|
async def get_reading(reading_id: int):
|
|
row = db_module.get_tarot_reading(reading_id)
|
|
if not row:
|
|
raise HTTPException(status_code=404, detail="reading not found")
|
|
return row
|
|
|
|
|
|
@router.patch("/readings/{reading_id}")
|
|
async def patch_reading(reading_id: int, req: TarotPatchRequest):
|
|
row = db_module.get_tarot_reading(reading_id)
|
|
if not row:
|
|
raise HTTPException(status_code=404, detail="reading not found")
|
|
db_module.update_tarot_reading(reading_id, **req.model_dump(exclude_none=True))
|
|
return {"ok": True}
|
|
|
|
|
|
@router.delete("/readings/{reading_id}")
|
|
async def delete_reading(reading_id: int):
|
|
row = db_module.get_tarot_reading(reading_id)
|
|
if not row:
|
|
raise HTTPException(status_code=404, detail="reading not found")
|
|
db_module.delete_tarot_reading(reading_id)
|
|
return {"ok": True}
|