def show_single_recipe(id): recipe = Recipe.get_by_id(id) step = Step.select().where(Step.recipe_id == id) recipe_ingredient = RecipeIngredient.select().where( RecipeIngredient.recipe_id == id) if recipe: step_data = [] for s in step: data = {"number": s.number, "description": s.description} step_data.append(data) ingredient_data = [] for i in recipe_ingredient: data = {"name": i.name} ingredient_data.append(data) results = { "id": recipe.id, "name": recipe.name, "image": recipe.image, "step": step_data, "ingredient": ingredient_data } return jsonify({"data": results})
def show_recipe_step(cuisine_name, recipe_name, step_number): cuisine = Cuisine.get_or_none(name=cuisine_name) if cuisine: recipe = Recipe.get_or_none(name=recipe_name) if recipe: if recipe.cuisine_id == cuisine.id: step = Step.select().where(Step.recipe_id == recipe.id, Step.number == step_number) for s in step: result = { "step_number": s.number, "description": s.description } return jsonify({"data": result}) else: return jsonify({ "errors": recipe_name + " is not found in " + cuisine_name + " cuisine." }) else: return jsonify({"errors": "Recipe not exists"}) else: return jsonify({"errors": cuisine_name + " cusine is not exist"})
def show_recipe_all_step(cuisine_name, recipe_name): cuisine = Cuisine.get_or_none(name=cuisine_name) if cuisine: recipe = Recipe.get_or_none(name=recipe_name) if recipe: step_all = Step.select().where(Step.recipe_id == recipe.id) results = [] for step in step_all: step_data = { "step_number": step.number, "step_description": step.description } results.append(step_data) return jsonify({"data": results}) else: return jsonify({ "errors": recipe_name + " is not found in " + cuisine_name + " cuisine." }) else: return jsonify({"errors": cuisine_name + " cusine is not exist"})