diff --git a/app/api/v1/person_images.py b/app/api/v1/person_images.py index 5c76e39..7a9b3d6 100644 --- a/app/api/v1/person_images.py +++ b/app/api/v1/person_images.py @@ -10,8 +10,21 @@ from app.schemas.person_image import ( from app.services import person_image as person_image_service from app.models.users import User from app.schemas.response import StandardResponse +from app.core.exceptions import BusinessError router = APIRouter() +@router.get("/default", tags=["person_images"]) +async def get_default_person_image( + db: AsyncSession = Depends(deps.get_db), + current_user: User = Depends(deps.get_current_user), +): + """获取当前用户的默认人物形象""" + image = await person_image_service.get_default_image(db=db, user_id=current_user.id) + if not image: + return BusinessError(code=404, message="默认人物形象不存在") + + return StandardResponse(code=200, message="获取默认人物形象成功", data=PersonImage.model_validate(image)) + @router.get("", tags=["person_images"]) async def get_person_images( db: AsyncSession = Depends(deps.get_db), @@ -30,7 +43,7 @@ async def get_person_images( return StandardResponse(code=200, message="获取人物形象成功", data=[PersonImage.model_validate(image) for image in images]) -@router.post("", response_model=PersonImage, tags=["person_images"]) +@router.post("", tags=["person_images"]) async def create_person_image( *, db: AsyncSession = Depends(deps.get_db), @@ -39,7 +52,9 @@ async def create_person_image( ): """创建新的人物形象""" image = await person_image_service.create_person_image(db=db, image=image_in, user_id= current_user.id) - + if not image: + return BusinessError(code=400, message="创建人物形象失败") + return StandardResponse(code=200, message="创建人物形象成功", data=PersonImage.model_validate(image))