修改前测post提交json
This commit is contained in:
@@ -1,13 +1,15 @@
|
||||
import logging
|
||||
from typing import Any, Optional
|
||||
|
||||
from fastapi import APIRouter, Depends, Query
|
||||
from fastapi import APIRouter, Depends, Query, Body
|
||||
|
||||
from sqlalchemy.ext.asyncio import AsyncSession
|
||||
from sqlalchemy import select
|
||||
from app.models.resources_material import ResourcesMaterial
|
||||
from app.models.pre_test_template import PreTestTemplate
|
||||
|
||||
from app.dependencies import get_db, get_current_user
|
||||
from app.schemas.resources_material import ResourcesMaterialListResponse
|
||||
from app.schemas.resources_material import ResourcesMaterialListResponse, PreTestMaterialRequest
|
||||
from app.services.resources_material_service import get_resources_material_list
|
||||
from app.services.pre_test_queue import pre_test_queue
|
||||
from app.utils.id_gen import generate_id
|
||||
@@ -58,8 +60,7 @@ async def get_resources_material_list_api(
|
||||
description="通过素材列表提交未前测的素材,异步处理,立即返回任务ID,结果稍后通过列表查询",
|
||||
)
|
||||
async def pre_test_material(
|
||||
resources_material_ids: list[str] = Query(..., description="资源素材表id"),
|
||||
pre_test_template_id: str = Query(..., description="前测模板id"),
|
||||
req: PreTestMaterialRequest = Body(..., description="前测请求体"),
|
||||
db: AsyncSession = Depends(get_db),
|
||||
current_user: dict = Depends(get_current_user),
|
||||
) -> Any | dict:
|
||||
@@ -72,16 +73,16 @@ async def pre_test_material(
|
||||
pre_test_template = await db.execute(
|
||||
select(PreTestTemplate)
|
||||
.where(
|
||||
PreTestTemplate.id == pre_test_template_id,
|
||||
PreTestTemplate.id == req.pre_test_template_id,
|
||||
PreTestTemplate.user_id == current_user.id,
|
||||
PreTestTemplate.deleted_at.is_(None),
|
||||
)
|
||||
)
|
||||
pre_test_template = pre_test_template.scalar_one_or_none()
|
||||
if not pre_test_template:
|
||||
return {"code": 1, "message": f"前测模板{pre_test_template_id}不存在或不属于当前用户"}
|
||||
return {"code": 1, "message": f"前测模板{req.pre_test_template_id}不存在或不属于当前用户"}
|
||||
|
||||
for resource_material_id in resources_material_ids:
|
||||
for resource_material_id in req.resources_material_ids:
|
||||
resource_material = await db.execute(
|
||||
select(ResourcesMaterial)
|
||||
.where(
|
||||
@@ -117,7 +118,6 @@ async def pre_test_material(
|
||||
})
|
||||
|
||||
if invalid_ids:
|
||||
logger.error(f"前测素材提交失败,无效素材ID: {'; '.join(invalid_ids)}")
|
||||
return {"code": 1, "message": "; ".join(invalid_ids)}
|
||||
|
||||
if not grouped_videos:
|
||||
@@ -128,7 +128,7 @@ async def pre_test_material(
|
||||
await pre_test_queue.enqueue({
|
||||
"task_id": task_id,
|
||||
"grouped_videos": grouped_videos,
|
||||
"pre_test_template_id": pre_test_template_id,
|
||||
"pre_test_template_id": req.pre_test_template_id,
|
||||
})
|
||||
|
||||
return {
|
||||
|
||||
@@ -56,4 +56,9 @@ class ResourcesMaterialListResponse(BaseModel):
|
||||
code: int = Field(0, description="返回码,0表示成功")
|
||||
message: str = Field("查询成功", description="返回消息")
|
||||
data: list[ResourcesMaterialOut] = Field(..., description="素材列表数据")
|
||||
total: int = Field(..., description="总记录数")
|
||||
total: int = Field(..., description="总记录数")
|
||||
|
||||
|
||||
class PreTestMaterialRequest(BaseModel):
|
||||
resources_material_ids: list[str] = Field(..., description="资源素材表id列表")
|
||||
pre_test_template_id: str = Field(..., description="前测模板id")
|
||||
Reference in New Issue
Block a user