mvc add filtration in search page
This commit is contained in:
parent
e2e27510da
commit
f6e5c71aba
@ -54,16 +54,20 @@ public class LibraryApplication implements CommandLineRunner {
|
|||||||
log.info("Create default authors values");
|
log.info("Create default authors values");
|
||||||
final var author1 = authorService.create(new AuthorEntity("author1"));
|
final var author1 = authorService.create(new AuthorEntity("author1"));
|
||||||
final var author2 = authorService.create(new AuthorEntity("author2"));
|
final var author2 = authorService.create(new AuthorEntity("author2"));
|
||||||
|
final var author3 = authorService.create(new AuthorEntity("author3"));
|
||||||
|
|
||||||
log.info("Create default books values");
|
log.info("Create default books values");
|
||||||
final var book1 = bookService.create(new BookEntity("book1", type1), new ArrayList<>());
|
final var book1 = bookService.create(new BookEntity("book1", type1), new ArrayList<>());
|
||||||
final var book2 = bookService.create(new BookEntity("book2", type1), new ArrayList<>());
|
final var book2 = bookService.create(new BookEntity("book2", type1), new ArrayList<>());
|
||||||
final var book3 = bookService.create(new BookEntity("book3", type2), new ArrayList<>());
|
final var book3 = bookService.create(new BookEntity("book3", type2), new ArrayList<>());
|
||||||
final var book4 = bookService.create(new BookEntity("book4", type2), new ArrayList<>());
|
final var book4 = bookService.create(new BookEntity("book4", type2), new ArrayList<>());
|
||||||
|
final var book5 = bookService.create(new BookEntity("book5", type2), new ArrayList<>());
|
||||||
|
|
||||||
bookService.addAuthor(author1.getId(), book1.getId());
|
bookService.addAuthor(author1.getId(), book1.getId());
|
||||||
bookService.addAuthor(author2.getId(), book2.getId());
|
|
||||||
bookService.addAuthor(author1.getId(), book3.getId());
|
bookService.addAuthor(author1.getId(), book3.getId());
|
||||||
|
bookService.addAuthor(author1.getId(), book4.getId());
|
||||||
|
bookService.addAuthor(author1.getId(), book5.getId());
|
||||||
|
bookService.addAuthor(author2.getId(), book2.getId());
|
||||||
bookService.addAuthor(author2.getId(), book3.getId());
|
bookService.addAuthor(author2.getId(), book3.getId());
|
||||||
|
|
||||||
log.info("Create default users values");
|
log.info("Create default users values");
|
||||||
|
@ -14,9 +14,11 @@ import org.springframework.web.bind.annotation.RequestParam;
|
|||||||
import org.springframework.web.servlet.mvc.support.RedirectAttributes;
|
import org.springframework.web.servlet.mvc.support.RedirectAttributes;
|
||||||
|
|
||||||
import com.ip.library.controllers.authors.AuthorEntity;
|
import com.ip.library.controllers.authors.AuthorEntity;
|
||||||
|
import com.ip.library.controllers.authors.AuthorService;
|
||||||
import com.ip.library.controllers.books.BookDto;
|
import com.ip.library.controllers.books.BookDto;
|
||||||
import com.ip.library.controllers.books.BookEntity;
|
import com.ip.library.controllers.books.BookEntity;
|
||||||
import com.ip.library.controllers.books.BookService;
|
import com.ip.library.controllers.books.BookService;
|
||||||
|
import com.ip.library.controllers.types.TypeService;
|
||||||
import com.ip.library.core.api.PageAttributesMapper;
|
import com.ip.library.core.api.PageAttributesMapper;
|
||||||
import com.ip.library.core.configuration.Constants;
|
import com.ip.library.core.configuration.Constants;
|
||||||
import com.ip.library.core.security.UserPrincipal;
|
import com.ip.library.core.security.UserPrincipal;
|
||||||
@ -27,19 +29,27 @@ public class UserBookController {
|
|||||||
private static final String USER_FAVORITES_VIEW = "user-favorites";
|
private static final String USER_FAVORITES_VIEW = "user-favorites";
|
||||||
private static final String PAGE_ATTRIBUTE = "page";
|
private static final String PAGE_ATTRIBUTE = "page";
|
||||||
private static final String AUTHOR_ATTRIBUTE = "authorId";
|
private static final String AUTHOR_ATTRIBUTE = "authorId";
|
||||||
|
private static final String AUTHORS_ATTRIBUTE = "authors";
|
||||||
private static final String TYPE_ATTRIBUTE = "typeId";
|
private static final String TYPE_ATTRIBUTE = "typeId";
|
||||||
|
private static final String TYPES_ATTRIBUTE = "types";
|
||||||
|
|
||||||
private final UserService userService;
|
private final UserService userService;
|
||||||
private final BookService bookService;
|
private final BookService bookService;
|
||||||
|
private final TypeService typeService;
|
||||||
|
private final AuthorService authorService;
|
||||||
private final ModelMapper modelMapper;
|
private final ModelMapper modelMapper;
|
||||||
|
|
||||||
public UserBookController(
|
public UserBookController(
|
||||||
UserService userService,
|
UserService userService,
|
||||||
BookService bookService,
|
BookService bookService,
|
||||||
ModelMapper modelMapper) {
|
ModelMapper modelMapper,
|
||||||
|
TypeService typeService,
|
||||||
|
AuthorService authorService) {
|
||||||
this.bookService = bookService;
|
this.bookService = bookService;
|
||||||
this.userService = userService;
|
this.userService = userService;
|
||||||
this.modelMapper = modelMapper;
|
this.modelMapper = modelMapper;
|
||||||
|
this.typeService = typeService;
|
||||||
|
this.authorService = authorService;
|
||||||
}
|
}
|
||||||
|
|
||||||
private BookDto toBookDto (BookEntity entity) {
|
private BookDto toBookDto (BookEntity entity) {
|
||||||
@ -93,6 +103,10 @@ public class UserBookController {
|
|||||||
bookService.getAll(typeId, authorId, page, Constants.DEFUALT_PAGE_SIZE),
|
bookService.getAll(typeId, authorId, page, Constants.DEFUALT_PAGE_SIZE),
|
||||||
this::toBookDto);
|
this::toBookDto);
|
||||||
model.addAllAttributes(attributes);
|
model.addAllAttributes(attributes);
|
||||||
|
model.addAttribute(TYPE_ATTRIBUTE, typeId);
|
||||||
|
model.addAttribute(AUTHOR_ATTRIBUTE, authorId);
|
||||||
|
model.addAttribute(TYPES_ATTRIBUTE, typeService.getAll());
|
||||||
|
model.addAttribute(AUTHORS_ATTRIBUTE, authorService.getAll());
|
||||||
model.addAttribute(PAGE_ATTRIBUTE, page);
|
model.addAttribute(PAGE_ATTRIBUTE, page);
|
||||||
return BOOK_SEARCH_VIEW;
|
return BOOK_SEARCH_VIEW;
|
||||||
}
|
}
|
||||||
|
@ -12,20 +12,26 @@
|
|||||||
<th:block th:case="*">
|
<th:block th:case="*">
|
||||||
<h2>Поиск</h2>
|
<h2>Поиск</h2>
|
||||||
<form method="get">
|
<form method="get">
|
||||||
<select id="typeId" name="typeId" th:value="*{typeId}">
|
<div class="mb-3">
|
||||||
<option value="-1">Выберите жанр</option>
|
<select class="form-control" id="typeId" name="typeId">
|
||||||
<option th:each="type : ${types}"
|
<option value="-1">Выберите жанр</option>
|
||||||
th:value="${type.Id}"
|
<option th:each="type : ${types}"
|
||||||
th:text="${type.name}">
|
th:value="${type.id}"
|
||||||
</option>
|
th:text="${type.name}"
|
||||||
</select>
|
th:selected="${type.id==typeId}">
|
||||||
<select id="authorId" name="authorId" th:value="*{authorId}">
|
</option>
|
||||||
<option value="-1">Выберите автора</option>
|
</select>
|
||||||
<option th:each="author : ${authors}"
|
</div>
|
||||||
th:value="${author.id}"
|
<div class="mb-3">
|
||||||
th:text="${author.name}">
|
<select class="form-control" id="authorId" name="authorId">
|
||||||
</option>
|
<option value="-1">Выберите автора</option>
|
||||||
</select>
|
<option th:each="author : ${authors}"
|
||||||
|
th:value="${author.id}"
|
||||||
|
th:text="${author.name}"
|
||||||
|
th:selected="${author.id==authorId}">
|
||||||
|
</option>
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
<button class="btn btn-primary me-2 button-fixed-width" type="submit">Обновить</button>
|
<button class="btn btn-primary me-2 button-fixed-width" type="submit">Обновить</button>
|
||||||
</form>
|
</form>
|
||||||
<table class="table">
|
<table class="table">
|
||||||
|
Loading…
Reference in New Issue
Block a user