Beispiel #1
0
    def put(self, name):
        data = Item.parser.parse_args()

        item_to_put = ItemModel.get_item_by_name(name)
        if item_to_put:
            try:
                item_to_put.price = data['price']
                item_to_put.store_id = data['store_id']
                item_to_put.save_to_db()
            except:
                # HTTP Code 500: Internal server error
                return {"message": "Error updating item !"}, 500
        else:
            try:
                item_to_put = ItemModel(name, data["price"], data['store_id'])
                item_to_put.save_to_db()
            except:
                # HTTP Code 500: Internal server error
                return {"message": "Error inserting item !"}, 500

        return item_to_put.json()
Beispiel #2
0
    def post(self, name):
        if ItemModel.get_item(name):
            # We already have this item
            result = {'message': f'An item with name {name} already exists.'}
            status = 400
        else:
            data = Item.parser.parse_args()
            item = ItemModel(
                name,
                data['price'],
                data['store_id'],
            )
            try:
                item.save_to_database()
                status = 201
                result = item.json()
            except:
                result = {'message': f'Internal Error Inserting Item: {name}'}
                status = 500

        return result, status
Beispiel #3
0
    def post(self, name):

        item = ItemModel.find_by_name(name)
        if item:
            return {
                'message':
                "An item with name '{}' already exists.".format(name)
            }, 400

        # if (next(filter(lambda x: x['name'] == name, items), None)) is not None:
        #     return {'message': "An item with name '{}' already exists.".format(name)}, 400
        # print("reached pos2")

        data = Item.parser.parse_args()

        #data = request.get_json(force = True) #Force = True means returns ok for difft datatypes
        item = ItemModel(name, data['price'], data['store_id'])

        try:
            item.save_to_db()
        except:
            return {'message': 'item could not be inserted into db'}, 500

        return item.json(), 201
Beispiel #4
0
    def put(self, name):
        try:
            data = Item.parser.parse_args()
            item = ItemModel.get_item(name)
            if item:
                # Item exists. Update it.
                item.price = data['price']
                item.store_id = data['store_id']
                status = 200
            else:
                item = ItemModel(
                    name,
                    data['price'],
                    data['store_id'],
                )
                status = 201

            item.save_to_database()
            result = item.json()
        except:
            result = {'message': f'Internal Error Putting Item: {name}'}
            status = 500

        return result, status
Beispiel #5
0
 def delete(self, name):
     item = ItemModel.find_by_name(name)
     if item:
         item.delete_from_db()
     return {'message': "Item '{}' Deleted".format(name)}
Beispiel #6
0
 def delete(self, name):
     item = ItemModel.find_by_name(name)
     if item:
         item.delete_item()
         return {'message': "Item: '{0}' deleted".format(name)}, 200
     return {'message': 'item with name {0} NOT FOUND!'.format(name)}, 404
Beispiel #7
0
 def get(cls, name):
     item = ItemModel.find_by_name(name)
     if item:
         return item.json()
     return {'message': ITEM_NOT_FOUND}, 404
Beispiel #8
0
 def get(self, name):
     # получаем данные обьекта из БД если он существует - возвращаем его
     item = ItemModel.find_by_name(name)
     if item:
         return item.json()
     return {"message": "item not found"}, 404
Beispiel #9
0
    def delete(self, name):
        item = ItemModel.find_by_name(name)
        if item:
            item.delete_from_db(name)

        return {'message': 'item deleted'}
Beispiel #10
0
 def get(self, name):
     result = ItemModel.find_by_name(name)
     if result:
         return {'item': result.json()}
     return {'message': 'item not found'}
Beispiel #11
0
 def delete(self, name):
     item = ItemModel.find_by_ItemName(name)
     if item:
         item.delete_from_database()
         return { 'message' : 'Item deleted'}
     return {'message': 'Item not exist'}
Beispiel #12
0
 def delete(self, name):
     del_item = ItemModel.find_by_name(name)
     if del_item:
         del_item.delete_from_db()
         return {"message": f"{name} was deleted succesfully"}, 201
     return {"message": f"{name} is not a recognized item"}, 400
Beispiel #13
0
 def get(self, name):
     item = ItemModel.find_by_name(name)
     if item is not None:
         return item.json()
     #If doesnt exist return error message
     return {"message": "Item not found"}
Beispiel #14
0
 def get(self, name):
     item = ItemModel.find_by_name(name)
     if item:
         return item.json()
     return {"message": f"The item {name} does not exist"}, 400
Beispiel #15
0
    def get(self, name):

        item = ItemModel.find_by_name(name)
        if item:
            return item.json()
        return {'message': 'The item was not found'}
Beispiel #16
0
 def get(self):
     return ItemModel.fetchAllItems()
Beispiel #17
0
 def get(self, item_name):
     item = ItemModel.find_by_name(item_name)
     if item:
         return item.json(), 200
     else:
         return {"item": None}, 404
Beispiel #18
0
    def get(self, item_name):
        item = ItemModel.find_by_name(item_name)
        if item:
            return item.json()

        return {"message": "item not found"}, 404
 def get(cls):
     return {"Items" : items_schema.dump(ItemModel.find_all())}, 200
Beispiel #20
0
 def get(self):
     return {'items': [item.json() for item in ItemModel.get_all_items()]}
Beispiel #21
0
 def delete(self, name):
     item = ItemModel.find_by_name(name)
     if item:
         item.delete_from_db()
         return {'message': 'Item deleted.'}
     return {'message': 'Item not found.'}, 404
Beispiel #22
0
 def get(self, name):
     item = ItemModel.get_item_by_name(name)
     if item:
         return item.json()
     return {'message': 'item not found'}, 404
Beispiel #23
0
 def delete(self, item_name):
     item = ItemModel.find_by_name(item_name)
     if item:
         item.delete_from_db()
     return {"message": "Item deleted"}
Beispiel #24
0
 def delete(self, name):
     item = ItemModel.get_item_by_name(name)
     if item:
         item.delete_item()
     return {"message": "item deleted"}, 200
Beispiel #25
0
 def delete(self, name):
     item = ItemModel.find_by_name(name)
     if item:
         item.delete_from_db()
         return {"message": "Item {0} deleted".format(name)}
     return {"message": "Item {0} not found".format(name)}
Beispiel #26
0
    def get(self):
        if max_user_requests(flask_jwt.current_identity.username):
            return max_requests_message(), 400

        return {'total items': ItemModel.count_all_items()}
Beispiel #27
0
 def delete(self, name):
     item = ItemModel.find_by_name(name)
     if not item:
         return {'message': 'item does not exist'}, 400
     item.delete_from_db()
     return {'message': 'item deleted'}, 200
Beispiel #28
0
 def get(self, name):
     row = ItemModel.find_by_name(name)
     if row:
         return {'item': row.json()}
     else:
         return {"message": "item not found"}, 404
Beispiel #29
0
 def get(self, name):
     item = ItemModel.find_by_name(name)
     if item:
         return item.json(), 200
     return {'message': "Item not found"}, 404
Beispiel #30
0
    def delete(self, name):
        item = ItemModel.find_by_name(name)
        if item:
            item.delete_from_db()

        return {"message": " item has been deleted"}, 200