From 4d0e671eb82c4ff6941905744dd10b856e16e725 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adri=C3=A1n=20Oliva?= Date: Fri, 26 May 2023 13:34:05 -0600 Subject: Added a GET request with filters. Path is "/todos/filter". You have to pass as a body the arguments "name" for searching inside the to do's name, "priority" for specifying a priority level (or "All") and/or "done" for specifying if the to do is "Done" or "Undone" (or "All"). --- src/main/java/com/encora/Main.java | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) (limited to 'src/main/java/com/encora/Main.java') diff --git a/src/main/java/com/encora/Main.java b/src/main/java/com/encora/Main.java index dbd3364..ac2a609 100644 --- a/src/main/java/com/encora/Main.java +++ b/src/main/java/com/encora/Main.java @@ -124,7 +124,7 @@ public class Main { } @GetMapping("/todos/{field}/{order}") @ResponseStatus(value=HttpStatus.OK) - public List getFilteredToDos(@PathVariable("field") SortingsFields field, @PathVariable("order") SortingOrders order) { + public List getSortedToDos(@PathVariable("field") SortingsFields field, @PathVariable("order") SortingOrders order) { Sort sortingMethod = Sort.by(String.valueOf(field)); if (Objects.equals(String.valueOf(order), "DESC")) { sortingMethod = sortingMethod.descending(); @@ -132,4 +132,19 @@ public class Main { return toDosRepository.findAll(sortingMethod); } + + + // Getting filtered to dos. + record toDoFilters ( + String name, + String priority, + String done + ) { + + } + @GetMapping("/todos/filter") + @ResponseStatus(value=HttpStatus.OK) + public List getFilteredToDos(@RequestBody toDoFilters filters) throws Exception { + return toDosRepository.findAllWithFilter(filters.name(), filters.priority(), filters.done()); + } } -- cgit v1.2.3