def delete(self, name):
     item = ItemModel.findItemByName(name)
     if item:
         item.delete_from_db()
         return {"message": name + " was deleted"}, 200
     return {
         "message":
         "The requested item is not found. " + name + " was not deleted"
     }, 400
 def put(self, name):
     # Note : any passed argument which is not included with an .add_argument will be rejected
     data = Item.parser.parse_args()  # get the data
     item = ItemModel.findItemByName(name)
     if item:
         item.price = data['price']
         item.store_id = data['store_id']
     else:
         item = ItemModel(name, **data)
     item.save_to_db()
     return item.json()
    def post(self, name):
        if ItemModel.findItemByName(name):
            return {
                "message": "the item {} has already existed".format(name)
            }, 400  # 400 for Bad request

        # data = request.get_json() # read the json payload sent in the request body
        # Note : any passed argument which is not included with an .add_argument will be rejected
        data = Item.parser.parse_args()  # get the data
        item = ItemModel(name, **data)
        item.save_to_db()
        return item.json(), 201
 def get(self, name):
     item = ItemModel.findItemByName(name)
     if item:
         return item.json()
     return {"message": name + " is not found"}, 404