def _parse(year, month): try: from models.meal import MealModel except ImportError: from app.models.meal import MealModel if MealModel.objects(date='{}-{:0>2}-{:0>2}'.format(year, month, 1)): return for index, meal in enumerate(api.get_monthly_menus(year, month)): if not index: continue MealModel(date='{}-{:0>2}-{:0>2}'.format(year, month, index), breakfast=meal.breakfast or ['급식이 없습니다.'], lunch=meal.lunch or ['급식이 없습니다.'], dinner=meal.dinner or ['급식이 없습니다.']).save()
def post(self, name): if MealModel.find_by_name(name): return {'message': "Meal '{}' already exists".format(name)}, 400 meal = MealModel(name) try: meal.save_to_db() except: return { 'message': 'An error occurred while creating the meal' }, 500 return meal.json(), 201
def post(self, name): if MealModel.find_by_name(name): return { 'message': 'An item with name {} already exists.'.format(name) } data = Meal.parser.parse_args() meal = MealModel(name, data['price'], data['description']) try: meal.save_to_db() except: return {'message': 'Something went wrong with creating meal.'}, 500 return meal.json()
def get(self, name): meal = MealModel.find_by_name(name) if meal: return meal.json() return {'message': 'Meal not found'}, 404
def delete(self, name): meal = MealModel.find_by_name(name) if meal: meal.delete_from_db() return {'message': 'Meal deleted'}