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