From 840a8f01d65e97a0662ec8b3aebb592d621724c2 Mon Sep 17 00:00:00 2001 From: Pekka Helenius Date: Tue, 22 Sep 2020 01:15:54 +0300 Subject: [PATCH] Add additional book ID check Signed-off-by: Pekka Helenius --- .../main/java/com/fjordtek/bookstore/web/BookController.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/bookstore/src/main/java/com/fjordtek/bookstore/web/BookController.java b/bookstore/src/main/java/com/fjordtek/bookstore/web/BookController.java index e8086be..9e6dc2d 100644 --- a/bookstore/src/main/java/com/fjordtek/bookstore/web/BookController.java +++ b/bookstore/src/main/java/com/fjordtek/bookstore/web/BookController.java @@ -204,7 +204,10 @@ public class BookController { HttpServletResponse responseData ) { - bookId = book.getId(); + // NOTE: We have a unique and non-nullable ISBN value for each book. + if (bookId != book.getId()) { + bindingResult.rejectValue("name", "error.user", "Wrong book"); + } if (bindingResult.hasErrors()) { responseData.setStatus(HttpServletResponse.SC_BAD_REQUEST);