示例#1
0
文件: items.py 项目: Daoortor/API_v4
 def post(self, name):
     if Item.get_item(name):
         return {'message': f"item [{name}] already exists"}, 400
     price = ItemResource.parser.parse_args()['price']
     item = Item(name=name, price=price)
     item.add_item()
     return {'name': name, 'price': price}, 201
示例#2
0
文件: items.py 项目: Daoortor/API_v4
    def post(self):
        items = request.json['items']
        bad_item_names = []
        for item in items:
            existing_item = Item.get_item(item['name'])
            if existing_item:
                bad_item_names.append(existing_item['name'])
        if bad_item_names:
            return {'message': f'items {bad_item_names} already exist'}, 400

        for item in items:
            new_item = Item(name=item['name'], price=item['price'])
            new_item.add_item()
        return {'items': items}, 201
示例#3
0
文件: items.py 项目: Daoortor/API_v4
 def get(self):
     items = Item.get_items()
     return {
         'items': [{
             'name': item.name,
             'price': item.price
         } for item in items]
     }
示例#4
0
文件: items.py 项目: Daoortor/API_v4
 def put(self, name):
     price = ItemResource.parser.parse_args()['price']
     if not Item.get_item(name):
         item = Item(name=name, price=price)
         item.add_item()
         return {'name': name, 'price': price}, 201
     Item.change_item(name, price)
     return {'name': name, 'price': price}, 200
示例#5
0
文件: items.py 项目: Daoortor/API_v4
 def delete(self):
     if not Item.get_items():
         return {'message': f'There are no items in the store'}, 400
     Item.delete_items()
     return {}, 204
示例#6
0
文件: items.py 项目: Daoortor/API_v4
 def delete(self, name):
     item = Item.get_item(name)
     if not item:
         return {'message': f"item {name} doesn't exist"}, 404
     item.delete_item()
     return {}, 204
示例#7
0
文件: items.py 项目: Daoortor/API_v4
 def get(self, name):
     item = Item.get_item(name)
     if not item:
         return {'message': f"item [{name}] doesn't exist"}, 404
     return {'name': item.name, 'price': item.price}, 200