Compare commits

...

3 Commits

Author SHA1 Message Date
Dmitry Isaenko 509d31e1d8 Add Author page 2024-01-11 21:56:11 +03:00
Dmitry Isaenko 7c0f3218fa update Search page: adding links to author 2024-01-11 21:55:59 +03:00
Dmitry Isaenko 448edad14c correct Book field access type 2024-01-11 21:55:19 +03:00
7 changed files with 97 additions and 8 deletions

View File

@ -0,0 +1,43 @@
package ru.redrise.marinesco;
import java.util.List;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import ru.redrise.marinesco.data.AuthorRepository;
import ru.redrise.marinesco.data.BookRepository;
import ru.redrise.marinesco.library.Author;
import ru.redrise.marinesco.library.Book;
@Controller
@RequestMapping("/author")
public class AuthorController {
private AuthorRepository authorRepository;
private BookRepository bookRepository;
public AuthorController(AuthorRepository authorRepository, BookRepository bookRepository){
this.authorRepository = authorRepository;
this.bookRepository = bookRepository;
}
@GetMapping("/{authorId}")
public String getPage(@PathVariable("authorId") Long authorId, Model model) {
final Author author = authorRepository.findById(authorId).orElse(null);
if (author == null){
model.addAttribute("Error", "Not found");
return "author";
}
List<Book> books = bookRepository.findAllByAuthorsContains(author);
model.addAttribute("author", author);
model.addAttribute("books", books);
return "author";
}
}

View File

@ -12,7 +12,7 @@ import ru.redrise.marinesco.library.Book;
@Controller
@RequestMapping("/book")
public class BookController {
BookRepository bookRepository;
private BookRepository bookRepository;
public BookController(BookRepository bookRepository){
this.bookRepository = bookRepository;

View File

@ -5,12 +5,16 @@ import java.util.List;
import org.springframework.data.repository.CrudRepository;
import org.springframework.stereotype.Repository;
import ru.redrise.marinesco.library.Author;
import ru.redrise.marinesco.library.Book;
@Repository
public interface BookRepository extends CrudRepository<Book, Integer>{
List<Book> findBySeriesContainingIgnoreCase(String title);
List<Book> findByTitleContainingIgnoreCase(String title);
List<Book> findAllByAuthorsContains(Author author);
}

View File

@ -234,3 +234,7 @@ button:hover {
padding: 3px;
background-color: #D00000;
}
.book_title{
font-weight: bold;
}

View File

@ -0,0 +1,37 @@
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org">
<head>
<title>Marinesco</title>
<link rel="icon" href="/favicon.svg" type="image/svg+xml">
<link rel="alternate icon" href="/favicon.png" type="image/png">
<link rel="stylesheet" th:href="@{/styles/styles.css}" />
</head>
<body>
<div class="page">
<div th:replace="~{fragments/header :: 'header'}"></div>
<div class="container base">
<span class="validationError" th:if="${Error} != null" th:text="${Error}"></span>
<div th:if="${author} != null">
<h3><span th:text="${author.authorName}"></span></h3>
<div th:each="book : ${books}">
<a th:href="${'/book/' + book.id}">
<span class="book_title" th:text="${book.title}"></span>
</a>
<br />
<div th:if="${book.series} != ''" th:text="${'Series: ' + book.series}">
<br />
</div>
<a th:href="${'/download/?container=' + book.container + '&file=' + book.fsFileName}" th:text="Download"></a>
<span th:text="${' (' + book.fileExtension + ' ' + book.fileSizeForHumans + ')'}"></span>
<p></p>
</div>
</div>
</div>
</div>
<div th:replace="~{fragments/footer :: 'footer'}"></div>
</body>
</html>

View File

@ -17,6 +17,7 @@
<br /><a href="/manage_users">/manage_users</a>
<br /><a href="/settings">/settings</a>
<br /><a href="/book/59992766">/book/59992766</a>
<br /><a href="/author/1">/author/1</a>
<br /><a href="/h2">H2</a>
<br />
<br />

View File

@ -21,15 +21,15 @@
<h3>Titles</h3>
<div th:each="book : ${books}">
<a th:href="${'/book/' + book.id}">
<span th:text="${book.title}"></span>
<span class="book_title" th:text="${book.title}"></span>
</a>
<br />
<div th:if="${book.series} != ''" th:text="${'Series: ' + book.series}">
<br />
</div>
<span th:if="${#lists.size(book.authors)} == 1" th:text="${book.authors[0].authorName}"></span>
<a th:if="${#lists.size(book.authors)} == 1" th:href="${'/author/' + book.authors[0].id}" th:text="${book.authors[0].authorName}"></a>
<span th:if="${#lists.size(book.authors)} > 1" th:each="author : ${book.authors}" >
<span th:text="${author.authorName} + ', '"></span>
<a th:href="${'/author/' + author.id}" th:text="${author.authorName}"></a>,
</span>
<br />
<a th:href="${'/download/?container=' + book.container + '&file=' + book.fsFileName}"
@ -43,17 +43,17 @@
<div th:if="${series} != null">
<hr>
<h3>Series</h3>
<div th:each="book : ${series}">
<div th:each="book : ${books}">
<a th:href="${'/book/' + book.id}">
<span th:text="${book.title}"></span>
<span class="book_title" th:text="${book.title}"></span>
</a>
<br />
<div th:if="${book.series} != ''" th:text="${'Series: ' + book.series}">
<br />
</div>
<span th:if="${#lists.size(book.authors)} == 1" th:text="${book.authors[0].authorName}"></span>
<a th:if="${#lists.size(book.authors)} == 1" th:href="${'/author/' + book.authors[0].id}" th:text="${book.authors[0].authorName}"></a>
<span th:if="${#lists.size(book.authors)} > 1" th:each="author : ${book.authors}" >
<span th:text="${author.authorName} + ', '"></span>
<a th:href="${'/author/' + author.id}" th:text="${author.authorName}"></a>,
</span>
<br />
<a th:href="${'/download/?container=' + book.container + '&file=' + book.fsFileName}"