From e366121acd2aeefd3ce70fd07c09d2bdbcfeb56b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adri=C3=A1n=20Oliva?= Date: Thu, 25 May 2023 19:35:12 -0600 Subject: 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. --- src/main/java/com/encora/Main.java | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'src/main/java') 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); + } } -- cgit v1.2.3