diff options
author | Adrián Oliva <adrian.oliva@cimat.mx> | 2023-05-25 19:35:12 -0600 |
---|---|---|
committer | Adrián Oliva <adrian.oliva@cimat.mx> | 2023-05-25 19:35:12 -0600 |
commit | e366121acd2aeefd3ce70fd07c09d2bdbcfeb56b (patch) | |
tree | c73548abe033ad6d2ea46f5c72a7e02c5892af99 /src/main | |
parent | f48cf17ecedade7502c4d09f6f7a90e84f3776f3 (diff) | |
download | ToDo-App-BE-e366121acd2aeefd3ce70fd07c09d2bdbcfeb56b.tar.gz ToDo-App-BE-e366121acd2aeefd3ce70fd07c09d2bdbcfeb56b.zip |
New PUT to set undone.
PUT request on path /todos/{id}/undone sets the to do with id {id} to
undone. It also resets the 'doneDate' variable.
Diffstat (limited to 'src/main')
-rw-r--r-- | src/main/java/com/encora/Main.java | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/src/main/java/com/encora/Main.java b/src/main/java/com/encora/Main.java index 108e657..97ad25f 100644 --- a/src/main/java/com/encora/Main.java +++ b/src/main/java/com/encora/Main.java @@ -70,4 +70,17 @@ public class Main { selectedToDo.setDoneDate(new Date()); toDosRepository.save(selectedToDo); } + + // Update a to do to set "done" as false. + @PutMapping("/todos/{id}/undone") + @ResponseStatus(value=HttpStatus.OK) + public void setUndone(@PathVariable("id") Integer id) { + ToDos selectedToDo = toDosRepository.getById(id); + if (selectedToDo == null) throw new toDoNotFound(); + if (!selectedToDo.isDone()) return; + + selectedToDo.setDone(false); + selectedToDo.setDoneDate(null); + toDosRepository.save(selectedToDo); + } } |