Beispiel #1
0
    def put(self, name):
        data = request.get_json()
        item = ItemModel.find_by_name(name)
        updated_item = ItemModel(name, data['price'])

        if item is None:
            item = ItemModel(name, data['price'])

        else:
            item.price = data['pirce']

        item.save_to_db()

        return item.json()
Beispiel #2
0
    def put(self, name):
        data = Item.parser.parse_args()
        item = ItemModel.find_by_name(name)
        #updated_item = ItemModel(name,data['price'])

        if item is None:
            item = ItemModel(name, data['price'], data['store_id'])

        else:
            item.price = data['price']
            item.store_id = data['store_id']

        item.save_to_db()

        return item.json()
Beispiel #3
0
    def post(self, name):
        if ItemModel.find_by_name(name):
            return {
                "message":
                "An item with {} has already been created".format(name)
            }, 400

        data = Item.parser.parse_args()

        item = ItemModel(name, data['price'])

        try:
            item.save_to_db()
        except:
            return {'message': ' An error occurred inserting item'}, 500

        return item.json(), 201