aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/com/encora/Main.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/com/encora/Main.java')
-rw-r--r--src/main/java/com/encora/Main.java16
1 files changed, 16 insertions, 0 deletions
diff --git a/src/main/java/com/encora/Main.java b/src/main/java/com/encora/Main.java
index ec23015..108e657 100644
--- a/src/main/java/com/encora/Main.java
+++ b/src/main/java/com/encora/Main.java
@@ -54,4 +54,20 @@ public class Main {
todo.setPriority(toDo.priority());
toDosRepository.save(todo);
}
+
+ // Update a to do with "done".
+ @ResponseStatus(value=HttpStatus.BAD_REQUEST, reason="No to do with such index.")
+ public static class toDoNotFound extends RuntimeException {}
+
+ @PostMapping("/todos/{id}/done")
+ @ResponseStatus(value=HttpStatus.OK)
+ public void setDone(@PathVariable("id") Integer id) {
+ ToDos selectedToDo = toDosRepository.getById(id);
+ if (selectedToDo == null) throw new toDoNotFound();
+ if (selectedToDo.isDone()) return;
+
+ selectedToDo.setDone(true);
+ selectedToDo.setDoneDate(new Date());
+ toDosRepository.save(selectedToDo);
+ }
}