23a31f7c00
- Add silent WeChat login for MP/browser environments - Fix Python 3.6 compatibility (remove typing.Annotated usage) - Marketing page: tab-based content generation with category support - Translate page: add auto-detect language default - Homepage: add TTS playback, announcement ticker, remove redundant quick-actions - Fix FAB button overlap with custom tabbar on customers/quotation pages - Make openai/anthropic imports lazy for Python 3.6 compat
90 lines
2.6 KiB
Python
90 lines
2.6 KiB
Python
from fastapi import APIRouter, Depends, HTTPException, Query
|
|
from sqlalchemy.ext.asyncio import AsyncSession
|
|
from typing import Optional
|
|
from app.database import get_db
|
|
from app.services.followup_engine import FollowupEngine
|
|
from app.api.v1.deps import get_current_user_id
|
|
|
|
router = APIRouter()
|
|
|
|
|
|
@router.get("/strategies")
|
|
async def list_strategies(
|
|
user_id: str = Depends(get_current_user_id),
|
|
db: AsyncSession = Depends(get_db),
|
|
):
|
|
engine = FollowupEngine(db)
|
|
await engine.ensure_default_strategies()
|
|
return {"strategies": await engine.get_strategies()}
|
|
|
|
|
|
@router.get("/pending")
|
|
async def get_pending_followups(
|
|
page: int = Query(1, ge=1),
|
|
size: int = Query(20, ge=1, le=100),
|
|
user_id: str = Depends(get_current_user_id),
|
|
db: AsyncSession = Depends(get_db),
|
|
):
|
|
engine = FollowupEngine(db)
|
|
return await engine.get_pending_followups(user_id, page, size)
|
|
|
|
|
|
@router.get("/logs")
|
|
async def get_followup_logs(
|
|
page: int = Query(1, ge=1),
|
|
size: int = Query(20, ge=1, le=100),
|
|
user_id: str = Depends(get_current_user_id),
|
|
db: AsyncSession = Depends(get_db),
|
|
):
|
|
engine = FollowupEngine(db)
|
|
return await engine.get_followup_logs(user_id, page, size)
|
|
|
|
|
|
@router.post("/{log_id}/send")
|
|
async def mark_followup_sent(
|
|
log_id: str,
|
|
user_id: str = Depends(get_current_user_id),
|
|
db: AsyncSession = Depends(get_db),
|
|
):
|
|
engine = FollowupEngine(db)
|
|
success = await engine.mark_sent(user_id, log_id)
|
|
if not success:
|
|
raise HTTPException(status_code=404, detail="Followup log not found")
|
|
return {"status": "ok"}
|
|
|
|
|
|
@router.post("/{log_id}/edit")
|
|
async def edit_and_send_followup(
|
|
log_id: str,
|
|
body: dict,
|
|
user_id: str = Depends(get_current_user_id),
|
|
db: AsyncSession = Depends(get_db),
|
|
):
|
|
edited_text = body.get("edited_text", "")
|
|
if not edited_text:
|
|
raise HTTPException(status_code=400, detail="edited_text is required")
|
|
engine = FollowupEngine(db)
|
|
success = await engine.mark_edited(user_id, log_id, edited_text)
|
|
if not success:
|
|
raise HTTPException(status_code=404, detail="Followup log not found")
|
|
return {"status": "ok"}
|
|
|
|
|
|
@router.get("/stats")
|
|
async def get_followup_stats(
|
|
user_id: str = Depends(get_current_user_id),
|
|
db: AsyncSession = Depends(get_db),
|
|
):
|
|
engine = FollowupEngine(db)
|
|
return await engine.get_stats(user_id)
|
|
|
|
|
|
@router.post("/scan")
|
|
async def trigger_followup_scan(
|
|
user_id: str = Depends(get_current_user_id),
|
|
db: AsyncSession = Depends(get_db),
|
|
):
|
|
engine = FollowupEngine(db)
|
|
result = await engine.scan_and_followup()
|
|
return result
|