Ejemplo n.º 1
0
    def delete(self, name):
        item = ItemModel.find(name)
        if not item:
            return {"item": None}, 404

        try:
            item.delete()
        except:
            return {"message": "An error occurred deleting the item"}, 500

        return {"message": "Item deleted"}
Ejemplo n.º 2
0
    def post(self, name):
        if ItemModel.find(name):
            return {"message": "Item {} already exists.".format(name)}, 400

        data = Item.parser.parse_args()
        item = ItemModel(name, **data)

        try:
            item.save()
            return item.json()
        except:
            return {"message": "An error occurred creating the item"}, 500
Ejemplo n.º 3
0
    def put(self, name):
        data = Item.parser.parse_args()

        item = ItemModel.find(name)
        if not item:
            item = ItemModel(name, **data)
        else:
            item.price = data["price"]
            item.store_id = data["store_id"]

        try:
            item.save()
            return item.json()
        except:
            return {"message": "An error occurred updating the item"}, 500
Ejemplo n.º 4
0
 def get(self, name):
     item = ItemModel.find(name)
     return ({"item": item.json()}, 200) if item \
         else ({"message": "Item {} not found".format(name)}, 404)