aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAdrián Oliva <adrian.oliva@cimat.mx>2023-05-25 13:24:43 -0600
committerAdrián Oliva <adrian.oliva@cimat.mx>2023-05-25 13:24:43 -0600
commita4dc3842ee6cdf1435f636e3a6dd3c91d579320b (patch)
tree9bc420d58ef79902d91c66747392b8432683558f /src
parent45ab8b99bf27e3923331d2d640463b65ee7ad818 (diff)
downloadToDo-App-BE-a4dc3842ee6cdf1435f636e3a6dd3c91d579320b.tar.gz
ToDo-App-BE-a4dc3842ee6cdf1435f636e3a6dd3c91d579320b.zip
Added HTTP responses and text has max length.
HTTP responses to each action. Raising an error when "text" has surpassed the 120 character limit.
Diffstat (limited to 'src')
-rw-r--r--src/main/java/com/encora/Main.java10
1 files changed, 10 insertions, 0 deletions
diff --git a/src/main/java/com/encora/Main.java b/src/main/java/com/encora/Main.java
index ed210d2..e9a0b24 100644
--- a/src/main/java/com/encora/Main.java
+++ b/src/main/java/com/encora/Main.java
@@ -2,6 +2,7 @@ package com.encora;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
+import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.*;
import java.util.Date;
@@ -25,10 +26,15 @@ public class Main {
}
@GetMapping("/todos")
+ @ResponseStatus(value=HttpStatus.OK)
public List<ToDos> getToDos() {
return toDosRepository.findAll();
}
+ @ResponseStatus(value=HttpStatus.BAD_REQUEST, reason="Text is longer than 120 characters.") // 404
+ public static class longerThanMaxException extends RuntimeException {
+ // ...
+ }
record NewToDo(
String text,
Date dueDate,
@@ -37,7 +43,11 @@ public class Main {
}
@PostMapping
+ @ResponseStatus(value=HttpStatus.OK)
public void addToDo(@RequestBody NewToDo toDo) {
+ if (toDo.text().length() > 120) {
+ throw new longerThanMaxException();
+ }
ToDos todo = new ToDos();
todo.setText(toDo.text());
todo.setDueDate(toDo.dueDate());