Browse Source

Minor refactoring

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

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

@ -251,12 +251,12 @@ public class Book {
@Override @Override
public String toString() { public String toString() {
return "[" + "id: " + this.id + ", " +
"title: " + this.title + ", " +
"author: " + this.author + ", " +
"year: " + this.year + ", " +
"isbn: " + this.isbn + ", " +
"price: " + this.price + ", " +
return "[" + "id: " + this.id + ", " +
"title: " + this.title + ", " +
"author: " + this.author + ", " +
"year: " + this.year + ", " +
"isbn: " + this.isbn + ", " +
"price: " + this.price + ", " +
"category: " + this.category + "]"; "category: " + this.category + "]";
} }


+ 5
- 5
bookstore/src/main/java/com/fjordtek/bookstore/model/Category.java View File

@ -32,9 +32,9 @@ public class Category {
private String name; private String name;
@OneToMany( @OneToMany(
mappedBy = "category"
//fetch = FetchType.LAZY,
//cascade = CascadeType.ALL
mappedBy = "category"
//fetch = FetchType.LAZY,
//cascade = CascadeType.ALL
) )
private List<Book> books; private List<Book> books;
@ -83,8 +83,8 @@ public class Category {
@Override @Override
public String toString() { public String toString() {
return "[" + "id: " + this.id + ", " +
"name: " + this.name + "]";
return "[" + "id: " + this.id + ", " +
"name: " + this.name + "]";
} }
} }

+ 16
- 19
bookstore/src/main/java/com/fjordtek/bookstore/web/BookController.java View File

@ -21,7 +21,6 @@ import org.springframework.web.bind.annotation.ResponseStatus;
import com.fjordtek.bookstore.model.Book; import com.fjordtek.bookstore.model.Book;
import com.fjordtek.bookstore.model.BookRepository; import com.fjordtek.bookstore.model.BookRepository;
import com.fjordtek.bookstore.model.Category;
import com.fjordtek.bookstore.model.CategoryRepository; import com.fjordtek.bookstore.model.CategoryRepository;
@Controller @Controller
@ -78,7 +77,7 @@ public class BookController {
) { ) {
Book newBook = new Book(); Book newBook = new Book();
dataModel.addAttribute("book", newBook);
dataModel.addAttribute("book", new Book());
dataModel.addAttribute("categories", categoryRepository.findAll()); dataModel.addAttribute("categories", categoryRepository.findAll());
dataModel.addAttribute("addpage", bookAddPageView); dataModel.addAttribute("addpage", bookAddPageView);
@ -97,8 +96,8 @@ public class BookController {
} }
@RequestMapping( @RequestMapping(
value = bookAddPageView,
method = RequestMethod.POST
value = bookAddPageView,
method = RequestMethod.POST
) )
public String webFormSaveNewBook( public String webFormSaveNewBook(
@Valid @ModelAttribute("book") Book book, @Valid @ModelAttribute("book") Book book,
@ -126,8 +125,8 @@ public class BookController {
// DELETE BOOK // DELETE BOOK
@RequestMapping( @RequestMapping(
value = bookDeletePageView + "/{id}",
method = RequestMethod.GET
value = bookDeletePageView + "/{id}",
method = RequestMethod.GET
) )
public String webFormDeleteBook( public String webFormDeleteBook(
@PathVariable("id") Long bookId, @PathVariable("id") Long bookId,
@ -148,8 +147,8 @@ public class BookController {
// UPDATE BOOK // UPDATE BOOK
@RequestMapping( @RequestMapping(
value = bookEditPageView + "/{id}",
method = { RequestMethod.GET }
value = bookEditPageView + "/{id}",
method = RequestMethod.GET
) )
public String webFormEditBook( public String webFormEditBook(
@PathVariable("id") Long bookId, @PathVariable("id") Long bookId,
@ -158,9 +157,8 @@ public class BookController {
) { ) {
Book book = bookRepository.findById(bookId).get(); Book book = bookRepository.findById(bookId).get();
Iterable<Category> categories = categoryRepository.findAll();
dataModel.addAttribute("book", book); dataModel.addAttribute("book", book);
dataModel.addAttribute("categories", categories);
dataModel.addAttribute("categories", categoryRepository.findAll());
dataModel.addAttribute("listpage", bookListPageView); dataModel.addAttribute("listpage", bookListPageView);
@ -179,8 +177,8 @@ public class BookController {
* but just as an URL end point. * but just as an URL end point.
*/ */
@RequestMapping( @RequestMapping(
value = bookEditPageView + "/{id}",
method = RequestMethod.POST
value = bookEditPageView + "/{id}",
method = RequestMethod.POST
) )
public String webFormUpdateBook( public String webFormUpdateBook(
@Valid @ModelAttribute("book") Book book, @Valid @ModelAttribute("book") Book book,
@ -191,8 +189,7 @@ public class BookController {
) { ) {
bookId = book.getId(); bookId = book.getId();
Iterable<Category> categories = categoryRepository.findAll();
dataModel.addAttribute("categories", categories);
dataModel.addAttribute("categories", categoryRepository.findAll());
if (bindingResult.hasErrors()) { if (bindingResult.hasErrors()) {
httpServerLogger.commonError("Book edit: error " + book.toString(), requestData); httpServerLogger.commonError("Book edit: error " + book.toString(), requestData);
@ -213,8 +210,8 @@ public class BookController {
// REDIRECTS // REDIRECTS
@RequestMapping( @RequestMapping(
value = { "/", landingPageView },
method = RequestMethod.GET
value = { "/", landingPageView },
method = RequestMethod.GET
) )
@ResponseStatus(HttpStatus.FOUND) @ResponseStatus(HttpStatus.FOUND)
public String redirectToDefaultWebForm() { public String redirectToDefaultWebForm() {
@ -223,7 +220,7 @@ public class BookController {
// Other URL requests // Other URL requests
@RequestMapping( @RequestMapping(
value = "*"
value = "*"
) )
public String errorWebForm(HttpServletRequest requestData) { public String errorWebForm(HttpServletRequest requestData) {
//return httpExceptionHandler.notFoundErrorHandler(requestData); //return httpExceptionHandler.notFoundErrorHandler(requestData);
@ -231,8 +228,8 @@ public class BookController {
} }
@RequestMapping( @RequestMapping(
value = "favicon.ico",
method = RequestMethod.GET
value = "favicon.ico",
method = RequestMethod.GET
) )
@ResponseBody @ResponseBody
public void faviconRequest() { public void faviconRequest() {


Loading…
Cancel
Save