Files
trade-assistant/backend/app/api/v1/interaction.py
T
TradeMate Dev 23a31f7c00 feat: silent wechat login, marketing tab optimization, admin page foundation
- 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
2026-05-14 00:30:48 +08:00

102 lines
3.2 KiB
Python

from fastapi import APIRouter, Depends, HTTPException
from sqlalchemy.ext.asyncio import AsyncSession
from app.database import get_db
from app.services.preference import UserPreferenceService
from app.services.marketing_effect import MarketingEffectService
from app.api.v1.deps import get_current_user_id
router = APIRouter()
@router.post("/select")
async def record_selection(
data: dict,
user_id: str = Depends(get_current_user_id),
db: AsyncSession = Depends(get_db),
):
message_id = data.get("message_id")
selected_index = data.get("selected_index")
if message_id is None or selected_index is None:
raise HTTPException(status_code=400, detail="message_id and selected_index required")
service = UserPreferenceService(db)
success = await service.record_selection(user_id, message_id, selected_index)
if not success:
raise HTTPException(status_code=404, detail="Message not found")
return {"status": "ok"}
@router.post("/edit")
async def record_edit(
data: dict,
user_id: str = Depends(get_current_user_id),
db: AsyncSession = Depends(get_db),
):
message_id = data.get("message_id")
edited_text = data.get("edited_text")
if not message_id or edited_text is None:
raise HTTPException(status_code=400, detail="message_id and edited_text required")
service = UserPreferenceService(db)
success = await service.record_edit(user_id, message_id, edited_text)
if not success:
raise HTTPException(status_code=404, detail="Message not found")
return {"status": "ok"}
@router.post("/analyze")
async def analyze_preferences(
user_id: str = Depends(get_current_user_id),
db: AsyncSession = Depends(get_db),
):
service = UserPreferenceService(db)
preferences = await service.analyze_preferences(user_id)
return preferences
@router.get("/preferences")
async def get_preferences(
user_id: str = Depends(get_current_user_id),
db: AsyncSession = Depends(get_db),
):
service = UserPreferenceService(db)
return await service.get_analysis(user_id)
@router.post("/marketing-effect")
async def track_marketing_effect(
data: dict,
user_id: str = Depends(get_current_user_id),
db: AsyncSession = Depends(get_db),
):
service = MarketingEffectService(db)
result = await service.track_event(
user_id=user_id,
content=data.get("content", ""),
product_id=data.get("product_id"),
product_name=data.get("product_name"),
channel=data.get("channel", "copy"),
event_type=data.get("event_type", "copy"),
target_audience=data.get("target_audience", ""),
metadata=data.get("metadata"),
)
return result
@router.get("/marketing-effects")
async def get_marketing_effects(
page: int = 1,
size: int = 20,
user_id: str = Depends(get_current_user_id),
db: AsyncSession = Depends(get_db),
):
service = MarketingEffectService(db)
return await service.get_effects(user_id, page, size)
@router.get("/marketing-effects/stats")
async def get_marketing_effect_stats(
user_id: str = Depends(get_current_user_id),
db: AsyncSession = Depends(get_db),
):
service = MarketingEffectService(db)
return await service.get_stats(user_id)