def get(self, name): recipe = RecipeModel.find_by_name(name) if recipe: return recipe.json(name) return { 'message': "There does not seem to be a recipe for that yet." }, 404
def put(self, name): data = Recipe.parser.parse_args() recipe = RecipeModel.find_by_name(name) if recipe: recipe.instructions = data['instructions'] else: recipe = RecipeModel(name, data['instructions']) recipe.save_to_db() return recipe.json()
def post(self): data = self.parser.parse_args() if RecipeModel.find_by_name(data['name']): return { 'message': "A recipe with name '{}' already exists.".format(data['name']) }, 400 recipe = RecipeModel(**data) try: recipe.save_to_db() except: return {"message": "An error occurred creating the recipe."}, 500 return recipe.json(), 201
def post(self, name): if RecipeModel.find_by_name(name): return { 'message': "A recipe with name '{}' already exists.".format(name) }, 400 data = Recipe.parser.parse_args() recipe = RecipeModel(name, data['instructions'], data['category_id']) try: recipe.save_to_db() except: return {"message": "An error occurred inserting the recipe."}, 500 return recipe.json(), 201
def delete(self, name): recipe = RecipeModel.find_by_name(name) if recipe: recipe.delete_from_db() return {'message': 'Recipe deleted'}
def get(self, name): recipe = RecipeModel.find_by_name(name) if recipe: return recipe.json() return {'message': 'Recipe not found'}, 404