Browse Source

Error if attempting to add a non-unique ISBN value

Signed-off-by: Pekka Helenius <fincer89@hotmail.com>
v0.0.1-alpha
Pekka Helenius 4 years ago
parent
commit
956bdad01d
2 changed files with 6 additions and 5 deletions
  1. +1
    -3
      bookstore/src/main/java/com/fjordtek/bookstore/model/Book.java
  2. +5
    -2
      bookstore/src/main/java/com/fjordtek/bookstore/web/BookController.java

+ 1
- 3
bookstore/src/main/java/com/fjordtek/bookstore/model/Book.java View File

@ -120,9 +120,7 @@ public class Book {
private int year;
//////////
@Column(
unique = true
)
@Column(unique = true)
@NotBlank(
message = "Fill the ISBN code form"
)


+ 5
- 2
bookstore/src/main/java/com/fjordtek/bookstore/web/BookController.java View File

@ -118,13 +118,16 @@ public class BookController {
HttpServletRequest requestData
) {
// TODO consider better solution. Add custom Hibernate annotation for Book class?
if (bookRepository.existsByIsbn(book.getIsbn())) {
bindingResult.rejectValue("isbn", "error.user", "ISBN code already exists");
}
if (bindingResult.hasErrors()) {
httpServerLogger.commonError("Book add: error " + book.toString(), requestData);
return bookAddPageView;
}
bookRepository.save(book);
httpServerLogger.logMessageNormal(
requestData,
bookAddPageView + ": " + "HTTPOK"


Loading…
Cancel
Save