|
@ -29,6 +29,12 @@ import com.fjordtek.bookstore.model.CategoryRepository; |
|
|
@Controller |
|
|
@Controller |
|
|
public class BookController { |
|
|
public class BookController { |
|
|
|
|
|
|
|
|
|
|
|
@Autowired |
|
|
|
|
|
private BookRepository bookRepository; |
|
|
|
|
|
|
|
|
|
|
|
@Autowired |
|
|
|
|
|
private CategoryRepository categoryRepository; |
|
|
|
|
|
|
|
|
private static final String landingPageView = "index"; |
|
|
private static final String landingPageView = "index"; |
|
|
private static final String bookListPageView = "booklist"; |
|
|
private static final String bookListPageView = "booklist"; |
|
|
private static final String bookAddPageView = "bookadd"; |
|
|
private static final String bookAddPageView = "bookadd"; |
|
@ -47,17 +53,12 @@ public class BookController { |
|
|
|
|
|
|
|
|
private HttpServerLogger httpServerLogger = new HttpServerLogger(); |
|
|
private HttpServerLogger httpServerLogger = new HttpServerLogger(); |
|
|
|
|
|
|
|
|
@Autowired |
|
|
|
|
|
private BookRepository bookRepository; |
|
|
|
|
|
|
|
|
|
|
|
@Autowired |
|
|
|
|
|
private CategoryRepository categoryRepository; |
|
|
|
|
|
|
|
|
|
|
|
@ModelAttribute |
|
|
@ModelAttribute |
|
|
public void globalAttributes(Model dataModel) { |
|
|
public void globalAttributes(Model dataModel) { |
|
|
|
|
|
|
|
|
// Security implications of adding these all controller-wide? |
|
|
// Security implications of adding these all controller-wide? |
|
|
dataModel.addAllAttributes(globalModelMap); |
|
|
dataModel.addAllAttributes(globalModelMap); |
|
|
|
|
|
dataModel.addAttribute("categories", categoryRepository.findAll()); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
////////////////////////////// |
|
|
////////////////////////////// |
|
@ -96,7 +97,6 @@ public class BookController { |
|
|
Book newBook = new Book(); |
|
|
Book newBook = new Book(); |
|
|
newBook.setYear(Year.now().getValue()); |
|
|
newBook.setYear(Year.now().getValue()); |
|
|
dataModel.addAttribute("book", newBook); |
|
|
dataModel.addAttribute("book", newBook); |
|
|
dataModel.addAttribute("categories", categoryRepository.findAll()); |
|
|
|
|
|
|
|
|
|
|
|
httpServerLogger.log(requestData, responseData); |
|
|
httpServerLogger.log(requestData, responseData); |
|
|
|
|
|
|
|
@ -166,7 +166,6 @@ public class BookController { |
|
|
|
|
|
|
|
|
Book book = bookRepository.findById(bookId).get(); |
|
|
Book book = bookRepository.findById(bookId).get(); |
|
|
dataModel.addAttribute("book", book); |
|
|
dataModel.addAttribute("book", book); |
|
|
dataModel.addAttribute("categories", categoryRepository.findAll()); |
|
|
|
|
|
|
|
|
|
|
|
httpServerLogger.log(requestData, responseData); |
|
|
httpServerLogger.log(requestData, responseData); |
|
|
|
|
|
|
|
@ -193,7 +192,6 @@ public class BookController { |
|
|
) { |
|
|
) { |
|
|
|
|
|
|
|
|
bookId = book.getId(); |
|
|
bookId = book.getId(); |
|
|
dataModel.addAttribute("categories", categoryRepository.findAll()); |
|
|
|
|
|
|
|
|
|
|
|
if (bindingResult.hasErrors()) { |
|
|
if (bindingResult.hasErrors()) { |
|
|
responseData.setStatus(HttpServletResponse.SC_BAD_REQUEST); |
|
|
responseData.setStatus(HttpServletResponse.SC_BAD_REQUEST); |
|
|