/
book.go
60 lines (49 loc) · 1.58 KB
/
book.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
package handlers
import (
"net/http"
"github.com/egnd/fb2lib/internal/entities"
"github.com/egnd/fb2lib/internal/repos"
"github.com/flosch/pongo2/v5"
"github.com/labstack/echo/v4"
)
func BookDetailsHandler(
repoBooks *repos.BooksLevelBleve,
repoLib *repos.LibraryFs,
) echo.HandlerFunc {
return func(c echo.Context) (err error) {
var book *entities.Book
if book, err = repoBooks.GetByID(c.Param("id")); err != nil {
c.NoContent(http.StatusNotFound)
return
}
if err = repoLib.AppendFB2Book(book); err != nil {
c.NoContent(http.StatusInternalServerError)
return
}
var seriesBooks, authorsBooks []entities.Book
var series entities.FreqsItems
if seriesBooks, err = repoBooks.GetSeriesBooks(100, book.Series(), book); err != nil {
c.NoContent(http.StatusInternalServerError)
return
}
repoLib.AppendFB2Books(seriesBooks)
if authorsBooks, err = repoBooks.GetAuthorsBooks(100, book.Authors(), book); err != nil {
c.NoContent(http.StatusInternalServerError)
return
}
repoLib.AppendFB2Books(authorsBooks)
if series, err = repoBooks.GetAuthorsSeries(book.Authors(), book.Series()); err != nil {
c.NoContent(http.StatusInternalServerError)
return
}
return c.Render(http.StatusOK, "pages/book.html", pongo2.Context{
"page_title": "Книга " + book.Info.Title,
"page_h1": book.Info.Title,
"book": book,
"series_books": seriesBooks,
"authors_books": authorsBooks,
"authors_series": series,
"breadcrumbs": (entities.BreadCrumbs{}).Push("Книги", "/books/").Push(book.Info.Title, ""),
})
}
}