提交 19b59bc2 编辑于 作者: Libcat's avatar Libcat 👷
浏览文件

- 优化用户地址管理的响应

- 修复能下空订单的问题
上级 acb46cd3
......@@ -27,6 +27,8 @@ async def get_order_by_id(id: int):
@router.post('/', response_model=api.OrderGet, description="创建订单")
async def create_one(order: api.OrderCreate):
dbitem = None
if len(order.items)==0:
return Response("订单不能为空", 403)
with dbconnection.atomic() as transaction:
# 先创建一个订单,总金额默认为0
......
from typing import List, Optional
from fastapi import APIRouter, Depends
from fastapi import APIRouter, Depends, Response
import apischemas as api
from database import *
......@@ -23,16 +23,16 @@ async def create_one(item: api.UserAddressBase,
return dbitem
@router.delete('/{id}', response_model=api.Response, description="删除地址")
@router.delete('/{id}', description="删除地址")
async def delete_one(id: int, user: User = Depends(get_user)):
dbitem: UserAddress = UserAddress.get_or_none(UserAddress.id == id, UserAddress.user_id==user.id)
if dbitem:
dbitem.delete_instance()
return api.Response(succ=True, msg="删除成功")
return Response("删除成功")
else:
return api.Response(succ=False, msg="该地址不存在")
return Response("该地址不存在", 403)
@router.put('/{id}', response_model=api.Response, description="修改地址")
@router.put('/{id}', description="修改地址")
async def modify_one(id: int, addr:api.UserAddressBase, user: User = Depends(get_user)):
dbitem: UserAddress = UserAddress.get_or_none(UserAddress.id == id, UserAddress.user_id==user.id)
......@@ -41,6 +41,6 @@ async def modify_one(id: int, addr:api.UserAddressBase, user: User = Depends(get
dbitem.address = addr.address
dbitem.phone = addr.phone
dbitem.save()
return api.Response(succ=True, msg="修改成功")
return Response("修改成功")
else:
return api.Response(succ=False, msg="该地址不存在")
\ No newline at end of file
return Response("该地址不存在", 403)
\ No newline at end of file
......@@ -127,7 +127,7 @@ async def delete_one(id: int, user: User = Depends(get_user)):
if dbitem:
if dbitem.id == user.id:
return Response("您不能删除自己的帐户", 400)
dbitem.delete_instance()
dbitem.delete_instance(recursive=True)
return Response("删除成功")
else:
return Response("该订单不存在", 404)
\ No newline at end of file
Supports Markdown
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册