def edit_recipe(user_id, id, recipe_id, **kwargs): """This route handles update a recipe by id""" title = str(request.data.get('title', '')).strip() description = str(request.data.get('description', '')).strip() identity = Category.find_user_by_id(id, user_id) if not identity: return jsonify( {"message": "You don't have" " that recipe in that category"}), 400 result2 = valid_recipe_title(title) if result2: return jsonify(result2), 400 title = title.lower() result = Recipe.find_by_id(title, id) if result and result.description == description: return jsonify({"message": "Recipe already exists"}), 400 recipe = Recipe.find_recipe_by_id(recipe_id, id) if not recipe: return jsonify({"message": "No recipes" " with that id to edit "}), 404 title = str(request.data.get('title', '')).lower() description = str(request.data.get('description', '')) recipe.title = title recipe.description = description recipe.save() return recipe.json(), 200
def get_recipe_by_id(user_id, id, recipe_id, **kwargs): """This route handles getting a recipe by id""" identity = Category.find_user_by_id(id, user_id) if not identity: return jsonify( {"message": "You don't have" " that recipe in that category"}), 400 recipe = Recipe.find_recipe_by_id(recipe_id, id) if not recipe: return jsonify({"message": "No recipes with" " that id to get"}), 400 return recipe.json(), 200
def delete_recipe(user_id, id, recipe_id, **kwargs): """This route handles deleting a recipe by id""" identity = Category.find_user_by_id(id, user_id) if not identity: return jsonify( {"message": "You don't have" " that recipe in that category"}), 400 recipe = Recipe.find_recipe_by_id(recipe_id, id) if not recipe: return jsonify({"message": "No recipes with" " that id to delete "}), 404 recipe.delete() return { "message": "recipe {} deleted" " successfully".format(recipe.title) }, 200