Add Author page

master
Dmitry Isaenko 2024-01-11 21:56:11 +03:00
parent 7c0f3218fa
commit 509d31e1d8
5 changed files with 89 additions and 0 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

@ -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 />