added backend server search functionality with unit tests
# Conflicts: # server/src/test/java/server/api/RecipeControllerTest.java
This commit is contained in:
parent
de8bdd60db
commit
eb5aedbe91
1 changed files with 23 additions and 0 deletions
|
|
@ -120,4 +120,27 @@ public class RecipeController {
|
||||||
messagingTemplate.convertAndSend(Topics.RECIPES, new DeleteRecipeMessage(id)); // Send to WS.
|
messagingTemplate.convertAndSend(Topics.RECIPES, new DeleteRecipeMessage(id)); // Send to WS.
|
||||||
return ResponseEntity.ok(true);
|
return ResponseEntity.ok(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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()){
|
||||||
|
String lowercaseSearch = search.toLowerCase();
|
||||||
|
recipes = recipes.stream().filter(recipe -> recipe.getName()
|
||||||
|
.toLowerCase()
|
||||||
|
.contains(lowercaseSearch))
|
||||||
|
.toList();
|
||||||
|
}
|
||||||
|
if(limit != null && limit<recipes.size()){
|
||||||
|
recipes = recipes.stream().limit(limit).toList();
|
||||||
|
}
|
||||||
|
return ResponseEntity.ok(recipes);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue