Class SpoonacularServiceImpl

java.lang.Object
com.cis.gorecipe.service.SpoonacularServiceImpl
All Implemented Interfaces:
SpoonacularService

@Service public class SpoonacularServiceImpl extends Object implements SpoonacularService
This class handles all interfacing with the Spoonacular Food and Recipe API
  • Field Details

    • logger

      org.slf4j.Logger logger
    • recipeRepository

      RecipeRepository recipeRepository
  • Constructor Details

    • SpoonacularServiceImpl

      public SpoonacularServiceImpl(RecipeRepository recipeRepository)
  • Method Details

    • sendGetRequest

      private com.google.gson.JsonElement sendGetRequest(String url) throws Exception
      Parameters:
      url - spoonacular API to get
      Returns:
      API results deserialized as JSON
      Throws:
      Exception
    • parseRecipe

      private Optional<Recipe> parseRecipe(com.google.gson.JsonObject result)
      Parameters:
      result - the JSON object representation of the recipe
      Returns:
      a Recipe object containing the information parsed from the JSON
    • search

      public List<Recipe> search(Map<String,​String> parameters) throws Exception
      Specified by:
      search in interface SpoonacularService
      Parameters:
      parameters - a map of the search parameters for the Spoonacular API (see https://rapidapi.com/spoonacular/api/recipe-food-nutrition/)
      Returns:
      a list of Recipe objects returned by the search
      Throws:
      Exception
    • recommend

      public List<Recipe> recommend(Set<Recipe> userRecipes) throws Exception
      Specified by:
      recommend in interface SpoonacularService
      Parameters:
      userRecipes - the list of recipes saved to a specific user account
      Returns:
      a list of recommended recipes based on the saved recipes
      Throws:
      Exception