Class RecipeService

java.lang.Object
ntnu.idatt2016.v233.SmartMat.service.product.RecipeService

@Service public class RecipeService extends Object
This class defines the methods for the recipe service
Version:
1.1
Author:
Stian Lyng, Birk
  • Constructor Details

    • RecipeService

      public RecipeService(RecipeRepository recipeRepository)
      Creates a new recipe service
      Parameters:
      recipeRepository - the recipe repository
  • Method Details

    • getRecipeById

      public Optional<Recipe> getRecipeById(Long id)
      Gets a recipe by its id
      Parameters:
      id - the id of the recipe
      Returns:
      an optional containing the recipe if it exists
    • getRecipesByName

      public List<Recipe> getRecipesByName(String name)
      Gets all recipes with a given name
      Parameters:
      name - the name of the recipe
      Returns:
      a list of recipes with the given name
    • getAllRecipes

      public List<Recipe> getAllRecipes()
      Gets all recipes
      Returns:
      a list of all recipes
    • saveRecipe

      public Recipe saveRecipe(Recipe recipe)
      Saves a recipe
      Parameters:
      recipe - the recipe to save
      Returns:
      the saved recipe
    • deleteRecipe

      public void deleteRecipe(Recipe recipe)
      Deletes a recipe
      Parameters:
      recipe - a recipe object to delete
    • deleteRecipeById

      public void deleteRecipeById(Long id)
      Deletes a recipe by its id
      Parameters:
      id - the id of the recipe to delete
    • addUserToRecipe

      public void addUserToRecipe(Recipe recipe, User user)
      Adds a user to a recipe used for adding favorite recipes
      Parameters:
      recipe - recipe to add user to
      user - 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 recipe
      name - 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 recipe
      name - name of the user
      Returns:
      ResponseEntity with succsess/fail message
    • getWeeklyMenu

      public List<RecipeWithMatchCount> getWeeklyMenu(Integer fridgeId)
      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