Package com.cis.gorecipe.controller
Class RecipeController
java.lang.Object
com.cis.gorecipe.controller.RecipeController
This class handles the API endpoints related to recipes
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate DietaryRestrictionRepositoryFor interfacing with the DietaryRestriction table in the databaseprivate IngredientRepositoryFor interfacing with the Ingredient table in the databaseprivate org.slf4j.LoggerFor logging any errors that occur during runtime (e.g.private RecipeRepositoryFor interfacing with the Recipe table in the databaseprivate SpoonacularServiceHandles all interactions with the Spoonacular APIprivate UserRepository -
Constructor Summary
ConstructorsConstructorDescriptionRecipeController(RecipeRepository recipeRepository, IngredientRepository ingredientRepository, UserRepository userRepository, DietaryRestrictionRepository dietaryRestrictionRepository, SpoonacularService spoonacularService) -
Method Summary
Modifier and TypeMethodDescriptionorg.springframework.http.ResponseEntity<Recipe>org.springframework.http.ResponseEntity<Void>deleteRecipe(Long id)org.springframework.http.ResponseEntity<Recipe>getRecommendedRecipes(Long userId)saveRecipes(List<Recipe> recipes)
-
Field Details
-
logger
private final org.slf4j.Logger loggerFor logging any errors that occur during runtime (e.g. a recipe is not found) -
recipeRepository
For interfacing with the Recipe table in the database -
ingredientRepository
For interfacing with the Ingredient table in the database -
userRepository
-
dietaryRestrictionRepository
For interfacing with the DietaryRestriction table in the database -
spoonacularService
Handles all interactions with the Spoonacular API
-
-
Constructor Details
-
RecipeController
public RecipeController(RecipeRepository recipeRepository, IngredientRepository ingredientRepository, UserRepository userRepository, DietaryRestrictionRepository dietaryRestrictionRepository, SpoonacularService spoonacularService)
-
-
Method Details
-
saveRecipes
-
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
- 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 intolerancesdiet- an optional comma separated string of 1 or more dietscuisine- an optional comma separated string of 1 or more cuisinesquery- 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
-