73 lines
2.3 KiB
Python
73 lines
2.3 KiB
Python
"""
|
|
互动管理 API
|
|
"""
|
|
from fastapi import APIRouter, Depends, HTTPException, Query
|
|
from sqlalchemy.orm import Session
|
|
from typing import Optional
|
|
|
|
from app.models.base import get_db
|
|
from app.models.interaction import InteractionType
|
|
from app.schemas.interaction import (
|
|
InteractionRecordResponse,
|
|
InteractionRecordListResponse,
|
|
InteractionExecuteRequest
|
|
)
|
|
from app.services.interaction_service import InteractionService, get_interaction_service
|
|
|
|
router = APIRouter()
|
|
|
|
|
|
@router.get("", response_model=InteractionRecordListResponse)
|
|
def get_interaction_records(
|
|
page: int = Query(1, ge=1, description="页码"),
|
|
page_size: int = Query(20, ge=1, le=100, description="每页数量"),
|
|
virtual_user_id: Optional[int] = Query(None, description="虚拟用户 ID"),
|
|
interaction_type: Optional[InteractionType] = Query(None, description="互动类型"),
|
|
db: Session = Depends(get_db),
|
|
service: InteractionService = Depends(get_interaction_service)
|
|
):
|
|
"""获取互动记录列表"""
|
|
# TODO: 实现筛选和分页查询
|
|
return {"total": 0, "items": []}
|
|
|
|
|
|
@router.get("/{record_id}", response_model=InteractionRecordResponse)
|
|
def get_interaction_record(
|
|
record_id: int,
|
|
db: Session = Depends(get_db),
|
|
service: InteractionService = Depends(get_interaction_service)
|
|
):
|
|
"""获取互动记录详情"""
|
|
# TODO: 实现详情查询
|
|
raise HTTPException(status_code=404, detail="Record not found")
|
|
|
|
|
|
@router.post("/execute", response_model=InteractionRecordResponse)
|
|
async def execute_interaction(
|
|
request: InteractionExecuteRequest,
|
|
db: Session = Depends(get_db),
|
|
service: InteractionService = Depends(get_interaction_service)
|
|
):
|
|
"""执行互动"""
|
|
record = await service.execute_interaction(
|
|
virtual_user_id=request.virtual_user_id,
|
|
interaction_type=request.interaction_type,
|
|
news_id=request.news_id
|
|
)
|
|
|
|
if not record:
|
|
raise HTTPException(status_code=400, detail="Failed to execute interaction")
|
|
|
|
return record
|
|
|
|
|
|
@router.post("/retry/{record_id}")
|
|
async def retry_interaction(
|
|
record_id: int,
|
|
db: Session = Depends(get_db),
|
|
service: InteractionService = Depends(get_interaction_service)
|
|
):
|
|
"""重试失败的互动"""
|
|
# TODO: 实现重试逻辑
|
|
raise HTTPException(status_code=404, detail="Record not found")
|