diff options
author | Adrián Oliva <adrian.oliva@cimat.mx> | 2023-05-26 08:10:08 -0600 |
---|---|---|
committer | Adrián Oliva <adrian.oliva@cimat.mx> | 2023-05-26 08:10:08 -0600 |
commit | 0dd1b42bf1008ed5cbc0f0f0afaa143248e75dd2 (patch) | |
tree | f495a2f021ae034e4ce770f613c8a819bdb49f87 /src/main | |
parent | d692dd22603c2762c21c2e0bef8f72f7025fe41a (diff) | |
download | ToDo-App-BE-0dd1b42bf1008ed5cbc0f0f0afaa143248e75dd2.tar.gz ToDo-App-BE-0dd1b42bf1008ed5cbc0f0f0afaa143248e75dd2.zip |
New DELETE request to delete a to do.
Path is "/todos/{id}" to delete a to do with id {id}.
Diffstat (limited to '')
-rw-r--r-- | src/main/java/com/encora/Main.java | 8 | ||||
-rw-r--r-- | src/main/java/com/encora/ToDosRepository.java | 19 |
2 files changed, 22 insertions, 5 deletions
diff --git a/src/main/java/com/encora/Main.java b/src/main/java/com/encora/Main.java index 47d72c0..dbd3364 100644 --- a/src/main/java/com/encora/Main.java +++ b/src/main/java/com/encora/Main.java @@ -79,6 +79,14 @@ public class Main { } + // Deletes a to do by index. + @DeleteMapping("/todos/{id}") + @ResponseStatus(value=HttpStatus.OK) + public void removeToDo(@PathVariable("id") Integer id) { + toDosRepository.deleteById(id); + } + + // Update a to do with "done". @PostMapping("/todos/{id}/done") @ResponseStatus(value=HttpStatus.OK) diff --git a/src/main/java/com/encora/ToDosRepository.java b/src/main/java/com/encora/ToDosRepository.java index 65c1b39..e7e939e 100644 --- a/src/main/java/com/encora/ToDosRepository.java +++ b/src/main/java/com/encora/ToDosRepository.java @@ -93,6 +93,20 @@ public class ToDosRepository implements JpaRepository<ToDos, Integer> { return null; } + // Delete a to do. + @Override + public void deleteById(Integer integer) { + ToDos selectedToDo; + + for (int index = 0; index < this.todos.size(); index++) { + selectedToDo = this.todos.get(index); + if (Objects.equals(selectedToDo.getId(), integer)) { + this.todos.remove(index); + break; + } + } + } + private Comparator<ToDos> getToDoComparator(Sort sort) throws Exception { // Personal function. Creates a `Comparator` based on the `sort` // parameter. This is for us to successfully sort our List without the @@ -231,11 +245,6 @@ public class ToDosRepository implements JpaRepository<ToDos, Integer> { } @Override - public void deleteById(Integer integer) { - - } - - @Override public void delete(ToDos entity) { } |