added comments
This commit is contained in:
parent
eb5aedbe91
commit
01ff1a96a9
1 changed files with 9 additions and 2 deletions
|
|
@ -121,20 +121,27 @@ public class RecipeController {
|
|||
return ResponseEntity.ok(true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Performs a search based on a case-insensitive parital match on
|
||||
* Recipe name and limits the result to a set amount of results.
|
||||
* @param search - name of the recipe to be searched for.
|
||||
* @param limit - limit of the results queried for.
|
||||
* @return - returns a ResponseEntity with a List of Recipes and an HTTP 200 ok status.
|
||||
*/
|
||||
public ResponseEntity<List<Recipe>> getRecipes(
|
||||
@RequestParam(required = false) String search,
|
||||
@RequestParam(required = false) Integer limit){
|
||||
|
||||
List<Recipe> recipes = recipeRepository.findAll();
|
||||
|
||||
if(search != null && !search.trim().isEmpty()){
|
||||
if(search != null && !search.trim().isEmpty()){ // if search isn't null or empty perform the filtering process
|
||||
String lowercaseSearch = search.toLowerCase();
|
||||
recipes = recipes.stream().filter(recipe -> recipe.getName()
|
||||
.toLowerCase()
|
||||
.contains(lowercaseSearch))
|
||||
.toList();
|
||||
}
|
||||
if(limit != null && limit<recipes.size()){
|
||||
if(limit != null && limit<recipes.size()){ // Limit the results if the limit is provided
|
||||
recipes = recipes.stream().limit(limit).toList();
|
||||
}
|
||||
return ResponseEntity.ok(recipes);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue