Exemplo n.º 1
0
    def put(self, dish_id):
        data = Dish.parser.parse_args()
        dish = DishModel.find_by_id(dish_id)

        if dish is None:
            dish = DishModel(dish_id, **data)
        else:
            dish.name = data['name']
            dish.price = data['price']
            dish.dish_type = data['dish_type']

        dish.save_to_db()
        return dish.json()
Exemplo n.º 2
0
    def post(self, dish_id):
        if DishModel.find_by_id(dish_id):
            return {
                'message': "A dish with id {} already exists".format(dish_id)
            }

        data = Dish.parser.parse_args()
        dish = DishModel(dish_id, **data)

        try:
            dish.save_to_db()

        except:
            return {'message': "An error occurred inserting the item."}, 500
        return dish.json(), 201
Exemplo n.º 3
0
    def delete(self, dish_id):
        dish = DishModel.find_by_id(dish_id)

        if dish:
            dish.delete_from_db()
            return {'message': 'Item deleted'}
Exemplo n.º 4
0
    def get(self, dish_id):
        dish = DishModel.find_by_id(dish_id)

        if dish:
            return dish.json()
        return {'message': "Dish not found"}, 404
Exemplo n.º 5
0
 def get(_id):
     dish = DishModel.load_dish_by_id(_id)
     return dish
Exemplo n.º 6
0
 def get(id_day, restaurant_type):
     return DishModel.load_dinner_dises(id_day, restaurant_type)
Exemplo n.º 7
0
 def get(id_day):
     return DishModel.load_lunch_dishes(id_day)
Exemplo n.º 8
0
 def get(id_day):
     return DishModel.load_random_dishes(id_day)
Exemplo n.º 9
0
 def get(id_day, meal_name, restaurant_type):
     random_dish = DishModel.load_random_dish_from_meal(
         id_day, meal_name, restaurant_type)
     return random_dish