From d0f608abaaf48cf72fddca24bdc2aff4c935d82e Mon Sep 17 00:00:00 2001 From: aaron <> Date: Mon, 14 Apr 2025 13:04:01 +0800 Subject: [PATCH] update --- app/api/v1/tryon.py | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/app/api/v1/tryon.py b/app/api/v1/tryon.py index c9fa72e..696dfb6 100644 --- a/app/api/v1/tryon.py +++ b/app/api/v1/tryon.py @@ -16,8 +16,9 @@ from app.models.tryon import TryonHistory, TryonStatus from app.schemas.tryon import TryonHistoryModel from app.core.exceptions import BusinessError from app.services import cos as cos_service +from app.schemas.person_image import PersonImage from sqlalchemy import select - +from sqlalchemy.orm import selectinload logger = logging.getLogger(__name__) logger.setLevel(logging.DEBUG) router = APIRouter() @@ -86,10 +87,25 @@ async def get_tryon_histories( """ 获取试穿历史 """ - histories = await db.execute(select(TryonHistory).where(TryonHistory.user_id == current_user.id).order_by(TryonHistory.create_time.desc())) + histories = await db.execute(select(TryonHistory).where(TryonHistory.user_id == current_user.id).order_by(TryonHistory.create_time.desc()).options(selectinload(TryonHistory.person_image))) tryon_histories = histories.scalars().all() - return StandardResponse(code=200, message="试穿历史获取成功", data=[TryonHistoryModel.model_validate(history) for history in tryon_histories]) + result = [] + for history in tryon_histories: + item = { + "id": history.id, + "person_image": PersonImage.model_validate(history.person_image), + "top_clothing_url": history.top_clothing_url, + "bottom_clothing_url": history.bottom_clothing_url, + "top_clothing_id": history.top_clothing_id, + "bottom_clothing_id": history.bottom_clothing_id, + "status": history.status, + "task_id": history.task_id, + "completion_url": history.completion_url, + } + result.append(item) + + return StandardResponse(code=200, message="试穿历史获取成功", data=result) @router.delete("/history/{history_id}", tags=["tryon"]) async def delete_tryon_history(