Esempio n. 1
0
 def get(self, name):
     try:
         item = ItemModel.find_item_by_name(name)
         if item:
             return item.json()
         return {"message": "Item not found"}, 404
     except:
         return {"Message": "An error occured while getting the item"}
Esempio n. 2
0
    def post(self):
        data = Item.parser.parse_args()

        if ItemModel.find_item_by_name(data["name"]):
            return {"message": "Error: Item already exists"}, 409

        item = ItemModel(**data)
        item.save()

        return item.json(), 201
Esempio n. 3
0
    def put(self, name):

        data = Item.parser.parse_args()

        try:
            item = ItemModel.find_item_by_name(name)
            if not item:
                item = ItemModel(**data)
            else:
                item.price = data["price"]
            item.save()

            return item.json()
        except:
            return {"message": "There was an error updating the item"}, 500
Esempio n. 4
0
 def delete(self, name):
     item = ItemModel.find_item_by_name(name)
     if item:
         item.delete()
         return {"message": "Item deleted successfully"}
     return {"message": "The item was not found"}, 404