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
This commit is contained in:
Rohan Sircar 2019-10-26 18:55:10 +05:30
parent d3ac95e8f4
commit febfaeec9a
10 changed files with 62 additions and 67 deletions

View File

@ -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<List<FieldError>>(bindingResult.getFieldErrors(),HttpStatus.BAD_REQUEST);
// return new ResponseEntity<ErrorResponse>(handleException(bindingResult), HttpStatus.BAD_REQUEST);
// }
BindingResult bindingResult, Principal principal) {
if (bindingResult.hasErrors()) {
// return new ResponseEntity<List<FieldError>>(bindingResult.getFieldErrors(),HttpStatus.BAD_REQUEST);
return new ResponseEntity<ErrorResponse>(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>(chatMessageDTO, responseHeader, HttpStatus.CREATED);
return new ResponseEntity<ChatMessageDTO>(chatMessageDTO, HttpStatus.CREATED);
}
/**

View File

@ -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;

View File

@ -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<ErrorModel> errorMessage;
}

View File

@ -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 {

View File

@ -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%;
}
} */
}

View File

@ -84,8 +84,8 @@
<label for="passphrase">Passphrase: </label>
<input class="form-control" type="password" id="passphrase" required>
</div>
<div class="form-group">
<button class="btn btn-secondary">Submit</button>
<div class="form-group text-center">
<button class="btn btn-secondary mx-auto">Submit</button>
</div>
</div>
</div>

View File

@ -29,7 +29,7 @@
<!-- <div class="jumbotron bg-primary"> -->
<div class="d-flex rounded">
<div class="p-4 align-self-end">
<div class="">
<h1 class="display-4">Chatto - Self Hosted, Minimal E2E Chat</h1>
<!-- <p th:if="${chatUser}" th:text="'username: ' + ${chatUser.userName}">You need to login</p>
<th:block th:each="userName: ${userNames}">

View File

@ -38,7 +38,7 @@
<header>
<div class="container">
<div class="row">
<div class="col-sm py-5">
<div class=" col-lg-5 offset-lg-3 py-5">
<!-- <h4 class="display-4 text-center py-2">Chat</h4> -->
<div class="card text-white bg-primary mb-3 text-center card-form rounded mx-auto" id="login-card">

View File

@ -15,9 +15,9 @@
<header>
<div class="container">
<div class="row">
<div class="col-sm py-5">
<div class="col-lg-5 offset-lg-3 py-5">
<!-- <h4 class="display-4 text-center py-2">Chat</h4> -->
<div class="card text-white bg-primary mb-3 card-form rounded mx-auto" id="login-card">
<div class="card text-white bg-primary mb-3 card-form rounded mx-auto" id="registration-card">
<div class="card-body rounded">
<!-- <h4 class="card-title">Chat</h4> -->

View File

@ -2,17 +2,13 @@
<html xmlns:th="http://www.thymeleaf.org">
<head>
<div th:replace="fragments/head :: headFragment">
<div th:replace="fragments/head :: headFragment">
<title id="pageTitle">User Home</title>
</div>
<script src="https://code.jquery.com/jquery-2.1.4.min.js" th:if="false"></script>
<script
src="http://blackpeppersoftware.github.io/thymeleaf-fragment.js/thymeleaf-fragment.js"
data-template-prefix="../" defer="defer" th:if="false"></script>
<link th:href="@{/css/master.css}" href="../../static/css/master.css"
rel="stylesheet" th:if="false">
<link th:href="@{/css/colors.css}" href="../../static/css/colors.css"
rel="stylesheet" th:if="false">
</div>
<script src="https://code.jquery.com/jquery-2.1.4.min.js" th:if="false"></script>
<script src="http://blackpeppersoftware.github.io/thymeleaf-fragment.js/thymeleaf-fragment.js" data-template-prefix="../" defer="defer" th:if="false"></script>
<link th:href="@{/css/master.css}" href="../../static/css/master.css" rel="stylesheet" th:if="false">
<link th:href="@{/css/colors.css}" href="../../static/css/colors.css" rel="stylesheet" th:if="false">
</head>
<body>
@ -24,8 +20,7 @@
<div class="col-sm py-5">
<!-- <h4 class="display-4 text-center py-2">Chat</h4> -->
<div
class="card text-white bg-primary mb-3 text-center card-form rounded mx-auto">
<div class="card text-white bg-primary mb-3 text-center card-form rounded mx-auto">
<h1 class="display-4">User Page</h1>
<div class="card-body rounded">
<!-- <h4 class="card-title">Chat</h4> -->