add delete history
This commit is contained in:
parent
b4bd051683
commit
62fe13c5e8
@ -91,6 +91,28 @@ async def get_tryon_histories(
|
|||||||
|
|
||||||
return StandardResponse(code=200, message="试穿历史获取成功", data=[TryonHistoryModel.model_validate(history) for history in tryon_histories])
|
return StandardResponse(code=200, message="试穿历史获取成功", data=[TryonHistoryModel.model_validate(history) for history in tryon_histories])
|
||||||
|
|
||||||
|
@router.delete("/history/{history_id}", tags=["tryon"])
|
||||||
|
async def delete_tryon_history(
|
||||||
|
history_id: int,
|
||||||
|
db: AsyncSession = Depends(deps.get_db),
|
||||||
|
current_user: User = Depends(get_current_user)
|
||||||
|
):
|
||||||
|
"""
|
||||||
|
删除试穿历史
|
||||||
|
"""
|
||||||
|
history = await db.execute(select(TryonHistory).where(TryonHistory.id == history_id))
|
||||||
|
tryon_history = history.scalar_one_or_none()
|
||||||
|
if not tryon_history:
|
||||||
|
raise BusinessError(code=404, message="试穿历史不存在")
|
||||||
|
if tryon_history.user_id != current_user.id:
|
||||||
|
raise BusinessError(code=403, message="无权限删除试穿历史")
|
||||||
|
|
||||||
|
await db.delete(tryon_history)
|
||||||
|
await db.commit()
|
||||||
|
|
||||||
|
return StandardResponse(code=200, message="试穿历史删除成功")
|
||||||
|
|
||||||
|
|
||||||
@router.get("/history/{history_id}", tags=["tryon"])
|
@router.get("/history/{history_id}", tags=["tryon"])
|
||||||
async def get_tryon_history(
|
async def get_tryon_history(
|
||||||
history_id: int,
|
history_id: int,
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user