Class RecipeService
java.lang.Object
ntnu.idatt2016.v233.SmartMat.service.product.RecipeService
This class defines the methods for the recipe service
- Version:
- 1.1
- Author:
- Stian Lyng, Birk
-
Constructor Summary
ConstructorsConstructorDescriptionRecipeService
(RecipeRepository recipeRepository) Creates a new recipe service -
Method Summary
Modifier and TypeMethodDescriptionorg.springframework.http.ResponseEntity<String>
addRecipeToFavorites
(Long recipeId, String name) Adds a recipe to a users favoritesvoid
addUserToRecipe
(Recipe recipe, User user) Adds a user to a recipe used for adding favorite recipesvoid
deleteRecipe
(Recipe recipe) Deletes a recipevoid
deleteRecipeById
(Long id) Deletes a recipe by its idGets all recipesgetRecipeById
(Long id) Gets a recipe by its idgetRecipesByName
(String name) Gets all recipes with a given namegetWeeklyMenu
(Integer fridgeId) Returns a list of RecipeWithMatchCount objects representing the weekly menu based on ingredients in a fridge.org.springframework.http.ResponseEntity<String>
removeRecipeFromFavorites
(Long recipeId, String name) Removes a recipe from a users favoritessaveRecipe
(Recipe recipe) Saves a recipe
-
Constructor Details
-
RecipeService
Creates a new recipe service- Parameters:
recipeRepository
- the recipe repository
-
-
Method Details
-
getRecipeById
Gets a recipe by its id- Parameters:
id
- the id of the recipe- Returns:
- an optional containing the recipe if it exists
-
getRecipesByName
Gets all recipes with a given name- Parameters:
name
- the name of the recipe- Returns:
- a list of recipes with the given name
-
getAllRecipes
Gets all recipes- Returns:
- a list of all recipes
-
saveRecipe
Saves a recipe- Parameters:
recipe
- the recipe to save- Returns:
- the saved recipe
-
deleteRecipe
Deletes a recipe- Parameters:
recipe
- a recipe object to delete
-
deleteRecipeById
Deletes a recipe by its id- Parameters:
id
- the id of the recipe to delete
-
addUserToRecipe
Adds a user to a recipe used for adding favorite recipes- Parameters:
recipe
- recipe to add user touser
- user to add to recipe
-
addRecipeToFavorites
public org.springframework.http.ResponseEntity<String> addRecipeToFavorites(Long recipeId, String name) Adds a recipe to a users favorites- Parameters:
recipeId
- id of the recipename
- name of the user- Returns:
- ResponsEntity with succsess/fail message
-
removeRecipeFromFavorites
public org.springframework.http.ResponseEntity<String> removeRecipeFromFavorites(Long recipeId, String name) Removes a recipe from a users favorites- Parameters:
recipeId
- id of the recipename
- name of the user- Returns:
- ResponseEntity with succsess/fail message
-
getWeeklyMenu
Returns a list of RecipeWithMatchCount objects representing the weekly menu based on ingredients in a fridge. The list contains recipes with matched ingredients and additional recipes with no matching ingredients (if there are less than 5 recipes with matching ingredients). Recipes with 0 match count are shuffled before returning.- Parameters:
fridgeId
- The ID of the fridge to get the weekly menu for- Returns:
- A list of RecipeWithMatchCount objects representing the weekly menu
-