Exemplo n.º 1
0
    def put(self, _id, store):
        parser = reqparse.RequestParser()

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

        food = FoodModel.find_by_store_id(_id, store)

        if (food):
            payload = parser.parse_args()

            if payload.get('name') is not None: food.name = payload['name']
            if payload.get('quantity') is not None: food.quantity = payload['quantity']
            if payload.get('calories') is not None: food.calories = payload['calories']
            if payload.get('expiration') is not None: food.expiration = datetime.datetime.strptime(payload['expiration'], '%m/%d/%Y')

            food.save()

            return {
                'status': 'ok',
                'message' : f'Food {_id} changed for store {store}'
            }
        else:
            return {
                'status'  : 'error',
                'message' : f'Food {_id} not found in store {store}'
            }, 404
Exemplo n.º 2
0
    def get(self, _id, store):
        food = FoodModel.find_by_store_id(_id, store)

        if food:
            return food.json()
        else:
            return {
                'status'  : 'error',
                'message' : f'Food {_id} not found in store {store}'
            }, 404
Exemplo n.º 3
0
    def delete(self, _id, store):
        food = FoodModel.find_by_store_id(_id, store)

        if food:
            food.delete()

            return {
                'status': 'ok',
                'message' : f'Food {_id} deleted for store {store}'
            }
        else:
            return {
                'status'  : 'error',
                'message' : f'Food {_id} not found in store {store}'
            }, 404