From febfaeec9a07766128d234347f0546972da3e98f Mon Sep 17 00:00:00 2001 From: Rohan Sircar Date: Sat, 26 Oct 2019 18:55:10 +0530 Subject: [PATCH] Changes to error model and login/registration cards Added json property names to error model Switched to grid offset instead of changing card width using CSS --- .../controller/ChatMessageController.java | 16 ++-- .../java/org/ros/chatto/error/ErrorModel.java | 5 ++ .../org/ros/chatto/error/ErrorResponse.java | 3 + .../org/ros/chatto/service/ChatService.java | 1 - .../src/main/resources/static/css/master.css | 15 ++-- chatto/src/main/resources/templates/chat.html | 4 +- chatto/src/main/resources/templates/home.html | 4 +- .../src/main/resources/templates/login.html | 2 +- .../resources/templates/registration.html | 4 +- .../main/resources/templates/user/home.html | 75 +++++++++---------- 10 files changed, 62 insertions(+), 67 deletions(-) diff --git a/chatto/src/main/java/org/ros/chatto/controller/ChatMessageController.java b/chatto/src/main/java/org/ros/chatto/controller/ChatMessageController.java index dacd7cd..dea8e60 100644 --- a/chatto/src/main/java/org/ros/chatto/controller/ChatMessageController.java +++ b/chatto/src/main/java/org/ros/chatto/controller/ChatMessageController.java @@ -17,7 +17,6 @@ import org.ros.chatto.error.ErrorResponse; import org.ros.chatto.service.ChatService; import org.ros.chatto.service.UserService; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.http.HttpHeaders; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; import org.springframework.validation.BindingResult; @@ -45,19 +44,18 @@ public class ChatMessageController { @PostMapping(value = "/post/message", consumes = { "application/json" }) @ResponseBody public ResponseEntity newMessage(@RequestBody @Valid ChatMessageDTO chatMessageDTO, - Principal principal) { -// if (bindingResult.hasErrors()) { -// -//// return new ResponseEntity>(bindingResult.getFieldErrors(),HttpStatus.BAD_REQUEST); -// return new ResponseEntity(handleException(bindingResult), HttpStatus.BAD_REQUEST); -// } + BindingResult bindingResult, Principal principal) { + if (bindingResult.hasErrors()) { + +// return new ResponseEntity>(bindingResult.getFieldErrors(),HttpStatus.BAD_REQUEST); + return new ResponseEntity(handleException(bindingResult), HttpStatus.BAD_REQUEST); + } MessageCipherDTO messageCipher = chatMessageDTO.getMessageCipher(); String fromUser = principal.getName(); String toUser = chatMessageDTO.getToUser(); System.out.println("Message cipher = " + messageCipher); chatMessageDTO = chatService.saveNewMessage(fromUser, toUser, messageCipher); - HttpHeaders responseHeader = new HttpHeaders(); - return new ResponseEntity(chatMessageDTO, responseHeader, HttpStatus.CREATED); + return new ResponseEntity(chatMessageDTO, HttpStatus.CREATED); } /** diff --git a/chatto/src/main/java/org/ros/chatto/error/ErrorModel.java b/chatto/src/main/java/org/ros/chatto/error/ErrorModel.java index 519edda..8e497c3 100644 --- a/chatto/src/main/java/org/ros/chatto/error/ErrorModel.java +++ b/chatto/src/main/java/org/ros/chatto/error/ErrorModel.java @@ -1,5 +1,7 @@ package org.ros.chatto.error; +import com.fasterxml.jackson.annotation.JsonProperty; + import lombok.AllArgsConstructor; import lombok.Data; import lombok.NoArgsConstructor; @@ -8,8 +10,11 @@ import lombok.NoArgsConstructor; @NoArgsConstructor @AllArgsConstructor public class ErrorModel{ + @JsonProperty("field_name") private String fieldName; + @JsonProperty("rejected_value") private Object rejectedValue; + @JsonProperty("error_message") private String messageError; diff --git a/chatto/src/main/java/org/ros/chatto/error/ErrorResponse.java b/chatto/src/main/java/org/ros/chatto/error/ErrorResponse.java index 42f9792..bec8e49 100644 --- a/chatto/src/main/java/org/ros/chatto/error/ErrorResponse.java +++ b/chatto/src/main/java/org/ros/chatto/error/ErrorResponse.java @@ -2,6 +2,8 @@ package org.ros.chatto.error; import java.util.List; +import com.fasterxml.jackson.annotation.JsonProperty; + import lombok.AllArgsConstructor; import lombok.Builder; import lombok.Data; @@ -12,6 +14,7 @@ import lombok.NoArgsConstructor; @NoArgsConstructor @AllArgsConstructor public class ErrorResponse { + @JsonProperty("errors") private List errorMessage; } \ No newline at end of file diff --git a/chatto/src/main/java/org/ros/chatto/service/ChatService.java b/chatto/src/main/java/org/ros/chatto/service/ChatService.java index e1d7106..83625af 100644 --- a/chatto/src/main/java/org/ros/chatto/service/ChatService.java +++ b/chatto/src/main/java/org/ros/chatto/service/ChatService.java @@ -8,7 +8,6 @@ import javax.validation.Valid; import org.ros.chatto.dto.ChatMessageDTO; import org.ros.chatto.dto.MessageCipherDTO; import org.ros.chatto.dto.ReencryptionDTO; -import org.ros.chatto.model.ChatMessage; import org.springframework.data.domain.PageRequest; public interface ChatService { diff --git a/chatto/src/main/resources/static/css/master.css b/chatto/src/main/resources/static/css/master.css index 569b3d5..e98bdc1 100644 --- a/chatto/src/main/resources/static/css/master.css +++ b/chatto/src/main/resources/static/css/master.css @@ -109,18 +109,13 @@ textarea { width: 80%; } -#login-card { + +/* #login-card { width: 40%; - /* margin: 0 auto; */ - /* Added */ - /* float: none; */ - /* Added */ - /* margin-bottom: 10px; */ - /* Added */ -} +} */ @media only screen and (max-width: 600px) { - #login-card { + /* #login-card { width: 90%; - } + } */ } \ No newline at end of file diff --git a/chatto/src/main/resources/templates/chat.html b/chatto/src/main/resources/templates/chat.html index a0511c0..a37c256 100644 --- a/chatto/src/main/resources/templates/chat.html +++ b/chatto/src/main/resources/templates/chat.html @@ -84,8 +84,8 @@ -
- +
+
diff --git a/chatto/src/main/resources/templates/home.html b/chatto/src/main/resources/templates/home.html index 1cfee96..b9be004 100644 --- a/chatto/src/main/resources/templates/home.html +++ b/chatto/src/main/resources/templates/home.html @@ -1,5 +1,5 @@ - +
@@ -29,7 +29,7 @@
-
+

Chatto - Self Hosted, Minimal E2E Chat

diff --git a/chatto/src/main/resources/templates/registration.html b/chatto/src/main/resources/templates/registration.html index 9f8844e..6c1513f 100644 --- a/chatto/src/main/resources/templates/registration.html +++ b/chatto/src/main/resources/templates/registration.html @@ -15,9 +15,9 @@
-
+
-
+
diff --git a/chatto/src/main/resources/templates/user/home.html b/chatto/src/main/resources/templates/user/home.html index 1624d70..77fbd70 100644 --- a/chatto/src/main/resources/templates/user/home.html +++ b/chatto/src/main/resources/templates/user/home.html @@ -2,56 +2,51 @@ -
- User Home -
- - - - +
+ User Home +
+ + + + -
+
-
-
-
-
- +
+
+
+
+ -
-

User Page

-
- - + - - + + -
+
-
-
- - + - -
-
-
-
-
-
-
-
-
+ + +
+
+
+
+
+
+
+