aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/com/encora/Main.java
diff options
context:
space:
mode:
authorAdrián Oliva <adrian.oliva@cimat.mx>2023-05-25 13:23:16 -0600
committerAdrián Oliva <adrian.oliva@cimat.mx>2023-05-25 13:23:16 -0600
commit45ab8b99bf27e3923331d2d640463b65ee7ad818 (patch)
tree418334a8928192c3e585b45c08e01bc886bf5bbc /src/main/java/com/encora/Main.java
parent0092d821aeca201321fd87b704ef0ad674f0d95b (diff)
downloadToDo-App-BE-45ab8b99bf27e3923331d2d640463b65ee7ad818.tar.gz
ToDo-App-BE-45ab8b99bf27e3923331d2d640463b65ee7ad818.zip
Added a POST endpoint.
Submit a JSON formatted body with the values "text", "dueDate" and "priority" to submit a new to do.
Diffstat (limited to 'src/main/java/com/encora/Main.java')
-rw-r--r--src/main/java/com/encora/Main.java19
1 files changed, 18 insertions, 1 deletions
diff --git a/src/main/java/com/encora/Main.java b/src/main/java/com/encora/Main.java
index 2989919..ed210d2 100644
--- a/src/main/java/com/encora/Main.java
+++ b/src/main/java/com/encora/Main.java
@@ -2,8 +2,9 @@ package com.encora;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
-import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.*;
+import java.util.Date;
import java.util.List;
@SpringBootApplication
@@ -27,4 +28,20 @@ public class Main {
public List<ToDos> getToDos() {
return toDosRepository.findAll();
}
+
+ record NewToDo(
+ String text,
+ Date dueDate,
+ Priority priority
+ ) {
+
+ }
+ @PostMapping
+ public void addToDo(@RequestBody NewToDo toDo) {
+ ToDos todo = new ToDos();
+ todo.setText(toDo.text());
+ todo.setDueDate(toDo.dueDate());
+ todo.setPriority(toDo.priority());
+ toDosRepository.save(todo);
+ }
}