From 0dd1b42bf1008ed5cbc0f0f0afaa143248e75dd2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adri=C3=A1n=20Oliva?= Date: Fri, 26 May 2023 08:10:08 -0600 Subject: New DELETE request to delete a to do. Path is "/todos/{id}" to delete a to do with id {id}. --- src/main/java/com/encora/ToDosRepository.java | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) (limited to 'src/main/java/com/encora/ToDosRepository.java') 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 { 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 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 @@ -230,11 +244,6 @@ public class ToDosRepository implements JpaRepository { return 0; } - @Override - public void deleteById(Integer integer) { - - } - @Override public void delete(ToDos entity) { -- cgit v1.2.3