Exemplo n.º 1
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
Exemplo n.º 2
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