def get(self, name):
        item = ItemModel.find_by_name(name)

        if item:
            return item.json()

        return {'message': 'Item not found'}, 404
Beispiel #2
0
    def get(self,name):
        item=ItemModel.find_by_name(name)

        if item:
            return item.json()
        else:
            return {"message":"item not found"},404
Beispiel #3
0
    def get(self):
        user_id=get_jwt_identity()
        items=[item.json() for item in ItemModel.find_all()]
        if user_id:
            return {"items":items}
        return {"items":[item["name"] for item in items],
                "message":"Login to see more data"

        }
Beispiel #4
0
    def delete(self,name):
        claims=get_jwt_claims()
        if not claims["isAdmin"]:
            return {"message":"Admin privilege required"},401
        item=ItemModel.find_by_name(name)
        if item:
            item.delete_from_db()

        return {"message":"item: {} deleted".format(name)}
    def put(self, name):
        data = Item.parser.parse_args()

        item = ItemModel.find_by_name(name)

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

        item.save_to_db()
        return item.json()
Beispiel #6
0
    def put(self,name):
        request_data=Item.parser.parse_args()
        item=ItemModel.find_by_name(name)

        if item is None:
            item = ItemModel(name, request_data["price"], request_data["store_id"])
        else:
            item.price=request_data["price"]

        item.save_to_db()

        return item.json()
Beispiel #7
0
    def post(self, name):
        if ItemModel.find_by_name(name):
            return {'message': 'An item with name: {} already exists'.format(name)},400
            
        request_data=Item.parser.parse_args()
        item=ItemModel(name, request_data["price"], request_data["store_id"])

        try:
            item.save_to_db()
        except Exception:
            return {'message':'can not insert item'},500
        
        return item.json(), 201
Beispiel #8
0
    def post(name):
        if ItemModel.find_by_name(name):
            return {
                'message': 'An item with name {} already exists.'.format(name)
            }, 400

        data = Item.parser.parse_args()

        item = ItemModel(name, **data)
        try:
            item.save_to_db()
        except:
            return {'message': 'Ann occurred inserting the item'}, 500

        return item.json(), 201
    def post(self, name):
        if ItemModel.find_by_name(name):
            return {
                'message':
                "An item with name '{}' already exists.".format(name)
            }, 400

        data = Item.parser.parse_args()
        #data = request.get_json() # params: force, silent

        item = ItemModel(name, **data)

        try:
            item.save_to_db()
        except:
            return {
                "message": "An error occurred inserting the item."
            }, 500  # Internal Server Error

        return item.json(), 201
    def delete(self, name):
        item = ItemModel.find_by_name(name)
        if item:
            item.delete_from_db()

        return {'message': 'Item deleted'}
Beispiel #11
0
 def get():
     return {'items': [item.json() for item in ItemModel.find_all()]}