Skip to content

Commit

Permalink
optimize gerne proccessing
Browse files Browse the repository at this point in the history
  • Loading branch information
HliasMpGH committed Sep 7, 2024
1 parent 2edb6c2 commit 887baa7
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 11 deletions.
6 changes: 3 additions & 3 deletions gui/src/main/java/gr/bibliotech/data/BookDAO.java
Original file line number Diff line number Diff line change
Expand Up @@ -87,11 +87,11 @@ public List<Book> filterBooks(List<Book> books, String filter) {
* @param genre the genre specified
* @return a list of books
*/
public List<Book> findBooks(String query, String genre) {
public List<Book> findBooks(String query, BookGenre genre) {
List<Book> books = (!query.trim().isEmpty() ? getMatchingBooks(query) : getBooks());

if (!genre.equals("any")) {
books = filterBooks(books, genre);
if (genre != BookGenre.ANY) {
books = filterBooks(books, genre.toString());
}

return books;
Expand Down
11 changes: 11 additions & 0 deletions gui/src/main/java/gr/bibliotech/data/BookGenre.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package gr.bibliotech.data;

/** The Available Book Genres. */
public enum BookGenre {
ANY,
ADVENTURE,
DRAMA,
CRIME,
DYSTOPIAN,
ROMANCE
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

import gr.bibliotech.app.Book;
import gr.bibliotech.data.BookDAO;
import gr.bibliotech.data.BookGenre;

/**
* The Controller that Handles
Expand Down Expand Up @@ -49,7 +50,7 @@ public String showResults(@RequestParam("query") String query,
Model model) {

// get the books that match the specified criteria
List<Book> matchingBooks = bookDAO.findBooks(query, genre);
List<Book> matchingBooks = bookDAO.findBooks(query, BookGenre.valueOf(genre));

// present the results, or an appropriate message in case of no results
if (matchingBooks.size() != 0) {
Expand Down
12 changes: 5 additions & 7 deletions gui/src/main/resources/templates/bookSearch.html
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,11 @@
<div class="filter-options">
<label for="genre">Genre:</label>
<select id="genre" name="genre">
<option value="any">Any</option>
<option value="adventure">Adventure</option>
<option value="drama">Drama</option>
<option value="crime">Crime</option>
<option value="Dystopian">Dystopian</option>
<option value="Romance">Romance</option>
<!-- Add more genre options as needed -->
<option
th:each = "genre : ${T(gr.bibliotech.data.BookGenre).values()}"
th:value = "${genre}"
th:text = "${genre}"
>
</select>
</div>
</form>
Expand Down

0 comments on commit 887baa7

Please sign in to comment.