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