コード例 #1
0
    def put(self, name):
        claims = get_jwt_claims()
        if not claims['is_admin']:
            return {'message': 'Admin privilege required.'}, 401

        data = Food.parser.parse_args()

        food = FoodModel.find_by_name(name)

        if food:
            food.price = data['price']
        else:
            food = FoodModel(name, **data)

        food.save_to_db()

        return food.json()
コード例 #2
0
ファイル: food.py プロジェクト: ThirioData/backend-api
 def post(self, food_name):
     food = FoodModel.find_by_food_name(food_name)
     if food:
         return {
             "message":
             "food food_name with '{}' already exists".format(food_name)
         }, 400, {
             'Access-Control-Allow-Origin': '*'
         }
     data = Food.parser.parse_args()
     food = FoodModel(data['food_name'], data['food_calorie'],
                      data['food_type'], data['food_cuisine'],
                      data['food_image'], data['food_category'],
                      data['food_description'], data['spice1'],
                      data['spice2'], data['spice3'], data['spice4'])
     try:
         food.save_to_db()
     except:
         return {"message": "Error occured durig insertion"}, 500
     return food.json(), 201
コード例 #3
0
    def post(self, name):
        claims = get_jwt_claims()
        if not claims['is_admin']:
            return {'message': 'Admin privilege required.'}, 401

        if FoodModel.find_by_name(name):
            return {
                'message': "A food with name '{}' already exists.".format(name)
            }, 400

        data = Food.parser.parse_args()
        print(data)
        food = FoodModel(name, **data)

        try:
            food.save_to_db()
        except:
            return {"message": "An error occurred inserting the food."}, 500

        return food.json(), 201
コード例 #4
0
    def post(self):
        parser = reqparse.RequestParser()

        parser.add_argument('name', type=str, required = True, help="Field name cannot be empty")
        parser.add_argument('quantity', type=int, required = True, help="Field name cannot be empty")
        parser.add_argument('calories', type=int, required = True, help="Field name cannot be empty")
        parser.add_argument('expiration', type=str, required = True, help="Field name cannot be empty")
        parser.add_argument('store', type=int, required = True, help="Field name cannot be empty")

        payload = parser.parse_args()

        expiration = datetime.datetime.strptime(payload['expiration'], '%m/%d/%Y')

        food = FoodModel(payload['name'], payload['quantity'], payload['calories'], expiration, payload['store'])
        food.save()
            
        return {
                'status'  : 'ok',
                'message' : 'Store created without issues',
                'record'  : food.json()                   
                }, 201        
コード例 #5
0
ファイル: food.py プロジェクト: ThirioData/backend-api
    def put(self, food_name):
        data = Food.parser.parse_args()
        food = FoodModel.find_by_food_name(food_name)

        if food is None:
            food = FoodModel(data['food_name'], data['food_calorie'],
                             data['food_type'], data['food_cuisine'],
                             data['food_image'], data['food_category'],
                             data['food_description'], data['spice1'],
                             data['spice2'], data['spice3'], data['spice4'])
        else:
            food.food_name = data['food_name']
            food.food_calorie = data['food_calorie']
            food.food_type = data['food_type']
            food.food_cuisine = data['food_cuisine']
            food.food_image = data['food_image']
            food.food_category = data['food_category']
            food.food_description = data['food_description']
            food.spice1 = data['spice1']
            food.spice2 = data['spice2']
            food.spice3 = data['spice3']
            food.spice4 = data['spice4']
        food.save_to_db()
        return food.json(), {'Access-Control-Allow-Origin': '*'}