Class RecipeController

java.lang.Object
com.cis.gorecipe.controller.RecipeController

@RestController @RequestMapping("/api/recipes") public class RecipeController extends Object
This class handles the API endpoints related to recipes
  • Field Details

    • logger

      private final org.slf4j.Logger logger
      For logging any errors that occur during runtime (e.g. a recipe is not found)
    • recipeRepository

      private final RecipeRepository recipeRepository
      For interfacing with the Recipe table in the database
    • ingredientRepository

      private final IngredientRepository ingredientRepository
      For interfacing with the Ingredient table in the database
    • userRepository

      private final UserRepository userRepository
    • dietaryRestrictionRepository

      private final DietaryRestrictionRepository dietaryRestrictionRepository
      For interfacing with the DietaryRestriction table in the database
    • spoonacularService

      private final SpoonacularService spoonacularService
      Handles all interactions with the Spoonacular API
  • Constructor Details

  • Method Details

    • saveRecipes

      private List<Recipe> saveRecipes(List<Recipe> recipes)
    • addRecipe

      @PostMapping("/") public org.springframework.http.ResponseEntity<Recipe> addRecipe(@RequestBody Recipe recipe)
      Parameters:
      recipe - a recipe to be added to GoRecipe's collection
      Returns:
      the recipe object created by the upload
    • deleteRecipe

      @DeleteMapping("/{id}") public org.springframework.http.ResponseEntity<Void> deleteRecipe(@PathVariable Long id)
      Parameters:
      id - the ID of the recipe to be removed
      Returns:
      an HTTP response confirming if the recipe has been removed from the system
    • getRecipe

      @GetMapping("/{id}") public org.springframework.http.ResponseEntity<Recipe> getRecipe(@PathVariable Long id)
      Parameters:
      id - the ID of the recipe to be fetched
      Returns:
      the recipe object that has been requested
    • getAllRecipes

      @GetMapping("/all") public org.springframework.http.ResponseEntity<List<Recipe>> getAllRecipes()
      Returns:
      a list of all recipes in the database
    • searchRecipes

      @GetMapping("/search") public org.springframework.http.ResponseEntity<List<Recipe>> searchRecipes(@RequestParam(name="intolerances",required=false) String intolerances, @RequestParam(name="diet",required=false) String diet, @RequestParam(name="cuisine",required=false) String cuisine, @RequestParam(name="query") String query, @RequestParam(name="ingredients",required=false) String ingredients) throws Exception
      Parameters:
      intolerances - an optional comma separated string of 1 or more intolerances
      diet - an optional comma separated string of 1 or more diets
      cuisine - an optional comma separated string of 1 or more cuisines
      query - a required string that should occur somewhere in the recipe (either recipe body or title)
      Returns:
      a list of recipes that meet the searchQuery parameters
      Throws:
      Exception
    • getRecommendedRecipes

      @GetMapping("/recommend/{userId}") public org.springframework.http.ResponseEntity<List<Recipe>> getRecommendedRecipes(@PathVariable Long userId) throws Exception
      Parameters:
      userId - the ID of the user whom we would like to recommend recipes to
      Returns:
      a list of recommended recipes
      Throws:
      Exception
    • getExplorePage

      @GetMapping("/explore") public org.springframework.http.ResponseEntity<Map<String,​List<Recipe>>> getExplorePage() throws Exception
      Returns:
      five lists of new recipes in different categories
      Throws:
      Exception