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()
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
def delete(self, dish_id): dish = DishModel.find_by_id(dish_id) if dish: dish.delete_from_db() return {'message': 'Item deleted'}
def get(self, dish_id): dish = DishModel.find_by_id(dish_id) if dish: return dish.json() return {'message': "Dish not found"}, 404
def get(_id): dish = DishModel.load_dish_by_id(_id) return dish
def get(id_day, restaurant_type): return DishModel.load_dinner_dises(id_day, restaurant_type)
def get(id_day): return DishModel.load_lunch_dishes(id_day)
def get(id_day): return DishModel.load_random_dishes(id_day)
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