Class RecipeController
java.lang.Object
edu.ntnu.idatt2106_2023_06.backend.controller.RecipeController
@RestController
@CrossOrigin("*")
@RequestMapping("/recipe")
public class RecipeController
extends Object
The RecipeController class is responsible for handling requests related to recipes. This includes loading recipes,
scraping recipes from external sources, and more.
- Author:
- Leon Egeberg Hesthaug, Trym Hamer Gudvangen
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionorg.springframework.http.ResponseEntity<Object>
acceptSuggestion
(RecipeShoppingDTO recipeShoppingDTO, Long recipeId, Long userId, org.springframework.security.core.Authentication authentication) This endpoint accepts a dinner suggestion and adds the recipe's ingredients to the user's shopping list.org.springframework.http.ResponseEntity<Object>
addIngredientToShoppingList
(RecipeShoppingDTO recipeShoppingDTO, org.springframework.security.core.Authentication authentication) This endpoint adds ingredients to the user's shopping list.org.springframework.http.ResponseEntity<Object>
addSuggestion
(RecipeSuggestionAddDTO recipeSuggestionAddDTO, org.springframework.security.core.Authentication authentication) This endpoint adds a dinner suggestion.org.springframework.http.ResponseEntity<Object>
denySuggestion
(Long fridgeId, Long recipeId, Long userId, org.springframework.security.core.Authentication authentication) This endpoint denies a dinner suggestion.org.springframework.http.ResponseEntity<Object>
This endpoint scrapes recipes from Meny.no's website, iteratively searching through their recipes.org.springframework.http.ResponseEntity<Object>
This endpoint generates item recipe scores between all items and recipes.org.springframework.http.ResponseEntity<Object>
generateItemRecipeScoresTest
(Long itemId, Long recipeId) This endpoint generates item recipe scores for a specific item and recipe.org.springframework.http.ResponseEntity<RecipeLoadDTO>
loadRecipe
(String recipeName) This endpoint retrieves a single recipe with the given name from Meny.org.springframework.http.ResponseEntity<org.springframework.data.domain.Page<RecipeLoadDTO>>
loadRecipe
(String recipeName, int page, int size) This endpoint retrieves a page of recipes with a given name from Meny, allowing for pagination.org.springframework.http.ResponseEntity<org.springframework.data.domain.Page<RecipeLoadDTO>>
loadRecipeByFridgeItems
(Long fridgeId, int page, int size) This endpoint retrieves a page of recipes from Meny that use ingredients in the given fridge, allowing for pagination.org.springframework.http.ResponseEntity<org.springframework.data.domain.Page<RecipeLoadDTO>>
loadRecipeByFridgeItemsAndDay
(Long fridgeId, Day day, int page, int size) This endpoint retrieves a page of recipes from Meny that use ingredients in the given fridge on the given day, allowing for pagination.org.springframework.http.ResponseEntity<Object>
loadSuggestion
(Long fridgeId) This endpoint loads the dinner suggestions for a given fridge.
-
Constructor Details
-
RecipeController
public RecipeController()
-
-
Method Details
-
downloadRecipe
@GetMapping("/download") public org.springframework.http.ResponseEntity<Object> downloadRecipe() throws IOExceptionThis endpoint scrapes recipes from Meny.no's website, iteratively searching through their recipes. Recipes are scraped using theRecipeScraper
class.- Returns:
- ResponseEntity with status code 200 (OK) if the scraping process completed without error.
- Throws:
IOException
- if an error occurs during the scraping process.
-
loadRecipe
@GetMapping("/get") public org.springframework.http.ResponseEntity<RecipeLoadDTO> loadRecipe(@RequestParam(name="recipe") String recipeName) This endpoint retrieves a single recipe with the given name from Meny.- Parameters:
recipeName
- The name of the recipe to retrieve.- Returns:
- ResponseEntity containing a RecipeLoadDTO object representing the requested recipe.
-
loadRecipe
@GetMapping("/load") public org.springframework.http.ResponseEntity<org.springframework.data.domain.Page<RecipeLoadDTO>> loadRecipe(@RequestParam(name="recipe") String recipeName, @RequestParam(name="page",defaultValue="0") int page, @RequestParam(name="size",defaultValue="10") int size) This endpoint retrieves a page of recipes with a given name from Meny, allowing for pagination.- Parameters:
recipeName
- The name of the recipes to retrieve.page
- The page number to retrieve.size
- The number of items to retrieve per page.- Returns:
- ResponseEntity containing a Page of RecipeLoadDTO objects representing the requested recipes.
-
loadRecipeByFridgeItems
@GetMapping("/loadByFridge") public org.springframework.http.ResponseEntity<org.springframework.data.domain.Page<RecipeLoadDTO>> loadRecipeByFridgeItems(@RequestParam(name="fridge") Long fridgeId, @RequestParam(name="page",defaultValue="0") int page, @RequestParam(name="size",defaultValue="10") int size) This endpoint retrieves a page of recipes from Meny that use ingredients in the given fridge, allowing for pagination.- Parameters:
fridgeId
- The ID of the fridge containing the ingredients to search for.page
- The page number to retrieve.size
- The number of items to retrieve per page.- Returns:
- ResponseEntity containing a Page of RecipeLoadDTO objects representing the requested recipes.
-
loadRecipeByFridgeItemsAndDay
@GetMapping("/loadByDay") public org.springframework.http.ResponseEntity<org.springframework.data.domain.Page<RecipeLoadDTO>> loadRecipeByFridgeItemsAndDay(@RequestParam(name="fridge") Long fridgeId, @RequestParam(name="day") Day day, @RequestParam(name="page",defaultValue="0") int page, @RequestParam(name="size",defaultValue="10") int size) This endpoint retrieves a page of recipes from Meny that use ingredients in the given fridge on the given day, allowing for pagination.- Parameters:
fridgeId
- The ID of the fridge containing the ingredients to search for.day
- The day of the week to search for recipes on.page
- The page number to retrieve.size
- The number of items to retrieve per page.- Returns:
- ResponseEntity containing a Page of RecipeLoadDTO objects representing the requested recipes.
-
generateItemRecipeScores
@PostMapping("/generateScores") public org.springframework.http.ResponseEntity<Object> generateItemRecipeScores()This endpoint generates item recipe scores between all items and recipes.- Returns:
- ResponseEntity with status 200 if the request is successful.
-
generateItemRecipeScoresTest
@PostMapping("/generateScoresTest") public org.springframework.http.ResponseEntity<Object> generateItemRecipeScoresTest(@RequestParam(name="item") Long itemId, @RequestParam(name="recipe") Long recipeId) This endpoint generates item recipe scores for a specific item and recipe.- Parameters:
itemId
- ID of the item to generate scores for.recipeId
- ID of the recipe to generate scores for.- Returns:
- ResponseEntity with status 200 if the request is successful.
-
addIngredientToShoppingList
@PostMapping("/addIngredients") public org.springframework.http.ResponseEntity<Object> addIngredientToShoppingList(@RequestBody RecipeShoppingDTO recipeShoppingDTO, org.springframework.security.core.Authentication authentication) This endpoint adds ingredients to the user's shopping list.- Parameters:
recipeShoppingDTO
- DTO containing information about the recipe and the user's fridge.authentication
- Authentication object containing the user's credentials.- Returns:
- ResponseEntity with status 200 if the request is successful.
- Throws:
UnauthorizedException
- if the user is not authenticated.
-
acceptSuggestion
@PostMapping("/suggestion/accept") public org.springframework.http.ResponseEntity<Object> acceptSuggestion(@RequestBody RecipeShoppingDTO recipeShoppingDTO, @RequestParam(name="recipe") Long recipeId, @RequestParam(name="user") Long userId, org.springframework.security.core.Authentication authentication) This endpoint accepts a dinner suggestion and adds the recipe's ingredients to the user's shopping list.- Parameters:
recipeShoppingDTO
- DTO containing information about the recipe and the user's fridge.recipeId
- ID of the recipe being accepted.userId
- ID of the user accepting the suggestion.authentication
- Authentication object containing the user's credentials.- Returns:
- ResponseEntity with status 200 if the request is successful.
- Throws:
UnauthorizedException
- if the user is not authenticated.
-
denySuggestion
@PostMapping("/suggestion/deny") public org.springframework.http.ResponseEntity<Object> denySuggestion(@RequestParam(name="fridge") Long fridgeId, @RequestParam(name="recipe") Long recipeId, @RequestParam(name="user") Long userId, org.springframework.security.core.Authentication authentication) This endpoint denies a dinner suggestion.- Parameters:
fridgeId
- The ID of the fridge where the recipe suggestion was made.recipeId
- The ID of the recipe that was suggested.userId
- The ID of the user who made the suggestion.authentication
- The authentication object for the current user.- Returns:
- ResponseEntity object with HTTP status 200 if the suggestion was successfully denied.
- Throws:
UnauthorizedException
- if the user is not authenticated.
-
addSuggestion
@PostMapping("/suggestion/add") public org.springframework.http.ResponseEntity<Object> addSuggestion(@RequestBody RecipeSuggestionAddDTO recipeSuggestionAddDTO, org.springframework.security.core.Authentication authentication) This endpoint adds a dinner suggestion.- Parameters:
recipeSuggestionAddDTO
- a DTO object representing the details of the recipe suggestion to be added.authentication
- the authentication object for the current user.- Returns:
- a ResponseEntity object with HTTP status 200 if the suggestion was successfully added.
- Throws:
UnauthorizedException
- if the user is not authenticated.
-
loadSuggestion
@GetMapping("/suggestion/load") public org.springframework.http.ResponseEntity<Object> loadSuggestion(@RequestParam(name="fridge") Long fridgeId) This endpoint loads the dinner suggestions for a given fridge.- Parameters:
fridgeId
- The ID of the fridge for which to load the suggestions.- Returns:
- ResponseEntity object with HTTP status 200 and a list of RecipeSuggestionLoad objects if the suggestions were loaded successfully.
-