|
|
@ -4,31 +4,26 @@ package com.fjordtek.bookstore.web; |
|
|
|
|
|
|
|
import org.springframework.stereotype.Controller; |
|
|
|
import org.springframework.ui.Model; |
|
|
|
import org.springframework.web.bind.annotation.ModelAttribute; |
|
|
|
import org.springframework.web.bind.annotation.PathVariable; |
|
|
|
import org.springframework.web.bind.annotation.RequestMapping; |
|
|
|
import org.springframework.web.bind.annotation.RequestMethod; |
|
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
|
//import org.springframework.web.bind.annotation.RequestParam; |
|
|
|
import org.springframework.http.HttpStatus; |
|
|
|
import org.springframework.web.bind.annotation.ResponseStatus; |
|
|
|
|
|
|
|
//import java.util.ArrayList; |
|
|
|
|
|
|
|
import javax.servlet.http.HttpServletRequest; |
|
|
|
//import javax.validation.Valid; |
|
|
|
|
|
|
|
import com.fjordtek.bookstore.model.*; |
|
|
|
|
|
|
|
@Controller |
|
|
|
public class BookController { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
protected static final String landingPageURL = "index"; |
|
|
|
protected static final String bookListPageURL = "booklist"; |
|
|
|
protected static final String bookAddPageURL = "bookadd"; |
|
|
|
protected static final String bookDeletePageURL = "bookdelete"; |
|
|
|
protected static final String bookSavePageURL = "booksave"; |
|
|
|
protected static final String bookEditPageURL = "bookedit"; |
|
|
|
|
|
|
|
private HttpServerLogger httpServerLogger = new HttpServerLogger(); |
|
|
|
private HttpExceptionHandler httpExceptionHandler = new HttpExceptionHandler(); |
|
|
@ -37,14 +32,14 @@ public class BookController { |
|
|
|
private BookRepository bookRepository; |
|
|
|
|
|
|
|
@RequestMapping( |
|
|
|
value = { bookListPageURL }, |
|
|
|
value = bookListPageURL, |
|
|
|
method = { RequestMethod.GET, RequestMethod.POST } |
|
|
|
) |
|
|
|
public String defaultWebFormGet(Model dataModel, HttpServletRequest requestData) { |
|
|
|
|
|
|
|
httpServerLogger.logMessageNormal( |
|
|
|
requestData, |
|
|
|
"HTTPOK" |
|
|
|
bookListPageURL + ": " + "HTTPOK" |
|
|
|
); |
|
|
|
|
|
|
|
dataModel.addAttribute("books", bookRepository.findAll()); |
|
|
@ -53,6 +48,9 @@ public class BookController { |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
////////////////////////////// |
|
|
|
// ADD BOOK |
|
|
|
|
|
|
|
@RequestMapping( |
|
|
|
value = bookAddPageURL, |
|
|
|
method = { RequestMethod.GET, RequestMethod.PUT } |
|
|
@ -61,23 +59,23 @@ public class BookController { |
|
|
|
|
|
|
|
httpServerLogger.logMessageNormal( |
|
|
|
requestData, |
|
|
|
"HTTPOK" |
|
|
|
bookAddPageURL + ": " + "HTTPOK" |
|
|
|
); |
|
|
|
|
|
|
|
dataModel.addAttribute("book", new Book()); |
|
|
|
|
|
|
|
return bookAddPageURL; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@RequestMapping( |
|
|
|
value = bookSavePageURL, |
|
|
|
value = bookAddPageURL, |
|
|
|
method = RequestMethod.POST |
|
|
|
) |
|
|
|
public String webFormSaveBook(Book book, HttpServletRequest requestData) { |
|
|
|
public String webFormSaveNewBook(Book book, HttpServletRequest requestData) { |
|
|
|
|
|
|
|
httpServerLogger.logMessageNormal( |
|
|
|
requestData, |
|
|
|
"HTTPOK" |
|
|
|
bookEditPageURL + ": " + "HTTPOK" |
|
|
|
); |
|
|
|
|
|
|
|
bookRepository.save(book); |
|
|
@ -85,27 +83,71 @@ public class BookController { |
|
|
|
return "redirect:" + bookListPageURL; |
|
|
|
} |
|
|
|
|
|
|
|
////////////////////////////// |
|
|
|
// DELETE BOOK |
|
|
|
|
|
|
|
@RequestMapping( |
|
|
|
value = bookDeletePageURL + "/{id}", |
|
|
|
method = RequestMethod.GET |
|
|
|
) |
|
|
|
public String webFormDeleteBook( |
|
|
|
@PathVariable("id") long bookId, |
|
|
|
Model dataModel, HttpServletRequest requestData |
|
|
|
) { |
|
|
|
HttpServletRequest requestData |
|
|
|
) { |
|
|
|
|
|
|
|
httpServerLogger.logMessageNormal( |
|
|
|
requestData, |
|
|
|
"HTTPOK" |
|
|
|
bookDeletePageURL + ": " + "HTTPOK" |
|
|
|
); |
|
|
|
|
|
|
|
bookRepository.deleteById(bookId); |
|
|
|
|
|
|
|
return "redirect:../" + bookListPageURL; |
|
|
|
} |
|
|
|
|
|
|
|
////////////////////////////// |
|
|
|
// UPDATE BOOK |
|
|
|
|
|
|
|
@RequestMapping( |
|
|
|
value = bookEditPageURL + "/{id}", |
|
|
|
method = RequestMethod.GET |
|
|
|
) |
|
|
|
public String webFormEditBook( |
|
|
|
@PathVariable("id") long bookId, |
|
|
|
Model dataModel, HttpServletRequest requestData |
|
|
|
) { |
|
|
|
|
|
|
|
httpServerLogger.logMessageNormal( |
|
|
|
requestData, |
|
|
|
bookEditPageURL + ": " + "HTTPOK" |
|
|
|
); |
|
|
|
|
|
|
|
Book book = bookRepository.findById(bookId).get(); |
|
|
|
dataModel.addAttribute("book", book); |
|
|
|
|
|
|
|
return bookEditPageURL; |
|
|
|
} |
|
|
|
|
|
|
|
@RequestMapping( |
|
|
|
value = bookEditPageURL + "/{id}", |
|
|
|
method = RequestMethod.POST |
|
|
|
) |
|
|
|
public String webFormUpdateBook(@ModelAttribute("book") Book book, HttpServletRequest requestData) { |
|
|
|
|
|
|
|
httpServerLogger.logMessageNormal( |
|
|
|
requestData, |
|
|
|
bookEditPageURL + ": " + "HTTPOK" |
|
|
|
); |
|
|
|
|
|
|
|
bookRepository.save(book); |
|
|
|
|
|
|
|
return "redirect:../" + bookListPageURL; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
////////////////////////////// |
|
|
|
// REDIRECTS |
|
|
|
|
|
|
|
// Redirect |
|
|
|
@RequestMapping( |
|
|
|
value = { "/", landingPageURL }, |
|
|
|
method = RequestMethod.GET |
|
|
|