From 8508aeb8b9eac96e8d41e85f5597f412e8fd971b Mon Sep 17 00:00:00 2001 From: aaron <> Date: Thu, 10 Apr 2025 19:01:37 +0800 Subject: [PATCH] update --- app/api/v1/clothing.py | 2 +- app/api/v1/person_images.py | 4 ++-- app/schemas/person_image.py | 5 +++-- app/services/clothing.py | 5 +++-- app/services/person_image.py | 8 ++++---- 5 files changed, 13 insertions(+), 11 deletions(-) diff --git a/app/api/v1/clothing.py b/app/api/v1/clothing.py index 11d9028..4aa1c8a 100644 --- a/app/api/v1/clothing.py +++ b/app/api/v1/clothing.py @@ -113,7 +113,7 @@ async def create_clothing( if category is None: raise BusinessError("指定的分类不存在", code=404) - clothing = await clothing_service.create_clothing(db=db, clothing=clothing) + clothing = await clothing_service.create_clothing(db=db, clothing=clothing, user_id=current_user.id) logger.info(f"创建衣服成功: id={clothing.id}") # 手动返回标准响应格式 return StandardResponse(code=200, data=Clothing.model_validate(clothing)) diff --git a/app/api/v1/person_images.py b/app/api/v1/person_images.py index 89cfc6e..4abeb52 100644 --- a/app/api/v1/person_images.py +++ b/app/api/v1/person_images.py @@ -35,11 +35,11 @@ async def create_person_image( *, db: AsyncSession = Depends(deps.get_db), current_user: User = Depends(deps.get_current_user), - image_in: PersonImage + image_in: PersonImageCreate ): """创建新的人物形象""" image_in.user_id = current_user.id - image = await person_image_service.create_person_image(db=db, image=image_in) + image = await person_image_service.create_person_image(db=db, image=image_in, user_id= current_user.id) return StandardResponse(code=200, message="创建人物形象成功", data=image) diff --git a/app/schemas/person_image.py b/app/schemas/person_image.py index 3d13944..757c12c 100644 --- a/app/schemas/person_image.py +++ b/app/schemas/person_image.py @@ -8,9 +8,10 @@ class PersonImageBase(BaseModel): image_url: str is_default: bool = False -class PersonImageCreate(PersonImageBase): +class PersonImageCreate(BaseModel): """创建人物形象请求模型""" - pass + image_url: str + is_default: bool = True class PersonImageUpdate(PersonImageBase): """更新人物形象请求模型""" diff --git a/app/services/clothing.py b/app/services/clothing.py index eaae9e5..f64ae52 100644 --- a/app/services/clothing.py +++ b/app/services/clothing.py @@ -84,11 +84,12 @@ async def get_clothes_by_category(db: AsyncSession, category_id: int, skip: int ) return result.scalars().all() -async def create_clothing(db: AsyncSession, clothing: ClothingCreate): +async def create_clothing(db: AsyncSession, clothing: ClothingCreate, user_id: int): """创建衣服""" db_clothing = Clothing( clothing_category_id=clothing.clothing_category_id, - image_url=clothing.image_url + image_url=clothing.image_url, + user_id=user_id ) db.add(db_clothing) await db.commit() diff --git a/app/services/person_image.py b/app/services/person_image.py index a35c4f0..5ce5618 100644 --- a/app/services/person_image.py +++ b/app/services/person_image.py @@ -21,17 +21,17 @@ async def get_person_images_by_user(db: AsyncSession, user_id: int, skip: int = ) return result.scalars().all() -async def create_person_image(db: AsyncSession, image: PersonImageCreate): +async def create_person_image(db: AsyncSession, image: PersonImageCreate, user_id: int): """创建人物形象 image: 包含user_id的PersonImageCreate对象 """ # 如果设置为默认形象,先重置用户的所有形象为非默认 - if image.is_default and image.user_id: - await reset_default_images(db, image.user_id) + if image.is_default: + await reset_default_images(db, user_id) db_image = PersonImage( - user_id=image.user_id, + user_id=user_id, image_url=image.image_url, is_default=image.is_default )