111 lines
3.7 KiB
Python
111 lines
3.7 KiB
Python
"""产品推介材料接口。"""
|
|||
|
|
|
||
|
|
from typing import Any
|
||
|
|
|
||
|
|
from fastapi import APIRouter, Depends, File, Header, Query, UploadFile
|
||
|
|
from sqlalchemy.ext.asyncio import AsyncSession
|
||
|
|
|
||
|
|
from app.api.dependencies.auth import build_request_context
|
||
|
|
from app.api.dependencies.database import get_session
|
||
|
|
from app.api.schemas.promotion_material import (
|
||
|
|
PromotionDeliveryRequest,
|
||
|
|
PromotionGenerationRequest,
|
||
|
|
PromotionInputsUpdate,
|
||
|
|
PromotionReviewRequest,
|
||
|
|
PromotionTaskCreate,
|
||
|
|
)
|
||
|
|
from app.core.contracts import RequestContext
|
||
|
|
from app.service.promotion_material_service import PromotionMaterialService
|
||
|
|
|
||
|
|
router = APIRouter(
|
||
|
|
prefix="/api/v1/fund-promotion-materials",
|
||
|
|
tags=["fund-promotion-materials"],
|
||
|
|
)
|
||
|
|
|
||
|
|
|
||
|
|
@router.post("")
|
||
|
|
async def create_task(
|
||
|
|
payload: PromotionTaskCreate,
|
||
|
|
context: RequestContext = Depends(build_request_context), # noqa: B008
|
||
|
|
key: str | None = Header(default=None, alias="Idempotency-Key"),
|
||
|
|
) -> dict[str, Any]:
|
||
|
|
return await PromotionMaterialService().create_task(payload, context, key)
|
||
|
|
|
||
|
|
|
||
|
|
@router.put("/{task_no}/inputs")
|
||
|
|
async def update_inputs(
|
||
|
|
task_no: str,
|
||
|
|
payload: PromotionInputsUpdate,
|
||
|
|
context: RequestContext = Depends(build_request_context), # noqa: B008
|
||
|
|
key: str | None = Header(default=None, alias="Idempotency-Key"),
|
||
|
|
) -> dict[str, Any]:
|
||
|
|
return await PromotionMaterialService().update_inputs(task_no, payload, context, key)
|
||
|
|
|
||
|
|
|
||
|
|
@router.post("/{task_no}/attachments")
|
||
|
|
async def add_attachment(
|
||
|
|
task_no: str,
|
||
|
|
file: UploadFile = File(...), # noqa: B008
|
||
|
|
attachment_type: str = Query(...),
|
||
|
|
context: RequestContext = Depends(build_request_context), # noqa: B008
|
||
|
|
key: str | None = Header(default=None, alias="Idempotency-Key"),
|
||
|
|
) -> dict[str, Any]:
|
||
|
|
payload = await file.read()
|
||
|
|
return await PromotionMaterialService().add_attachment(
|
||
|
|
task_no,
|
||
|
|
attachment_type,
|
||
|
|
file.filename or "attachment",
|
||
|
|
file.content_type or "application/octet-stream",
|
||
|
|
payload,
|
||
|
|
context,
|
||
|
|
key,
|
||
|
|
)
|
||
|
|
|
||
|
|
|
||
|
|
@router.post("/{task_no}/generations")
|
||
|
|
async def generate_material(
|
||
|
|
task_no: str,
|
||
|
|
payload: PromotionGenerationRequest,
|
||
|
|
context: RequestContext = Depends(build_request_context), # noqa: B008
|
||
|
|
key: str | None = Header(default=None, alias="Idempotency-Key"),
|
||
|
|
) -> dict[str, Any]:
|
||
|
|
return await PromotionMaterialService().generate(task_no, payload, context, key)
|
||
|
|
|
||
|
|
|
||
|
|
@router.get("/{task_no}/compliance-checks")
|
||
|
|
async def compliance_checks(
|
||
|
|
task_no: str,
|
||
|
|
context: RequestContext = Depends(build_request_context), # noqa: B008
|
||
|
|
session: AsyncSession = Depends(get_session), # noqa: B008
|
||
|
|
) -> dict[str, Any]:
|
||
|
|
return await PromotionMaterialService(session).compliance_checks(task_no, context)
|
||
|
|
|
||
|
|
|
||
|
|
@router.get("/{task_no}")
|
||
|
|
async def get_task(
|
||
|
|
task_no: str,
|
||
|
|
context: RequestContext = Depends(build_request_context), # noqa: B008
|
||
|
|
session: AsyncSession = Depends(get_session), # noqa: B008
|
||
|
|
) -> dict[str, Any]:
|
||
|
|
return await PromotionMaterialService(session).get_task(task_no, context)
|
||
|
|
|
||
|
|
|
||
|
|
@router.post("/{task_no}/reviews")
|
||
|
|
async def review_material(
|
||
|
|
task_no: str,
|
||
|
|
payload: PromotionReviewRequest,
|
||
|
|
context: RequestContext = Depends(build_request_context), # noqa: B008
|
||
|
|
key: str | None = Header(default=None, alias="Idempotency-Key"),
|
||
|
|
) -> dict[str, Any]:
|
||
|
|
return await PromotionMaterialService().review(task_no, payload, context, key)
|
||
|
|
|
||
|
|
|
||
|
|
@router.post("/{task_no}/deliveries")
|
||
|
|
async def deliver_material(
|
||
|
|
task_no: str,
|
||
|
|
payload: PromotionDeliveryRequest,
|
||
|
|
context: RequestContext = Depends(build_request_context), # noqa: B008
|
||
|
|
key: str | None = Header(default=None, alias="Idempotency-Key"),
|
||
|
|
) -> dict[str, Any]:
|
||
|
|
return await PromotionMaterialService().deliver(task_no, payload, context, key)
|