-
Notifications
You must be signed in to change notification settings - Fork 0
/
search.go
36 lines (28 loc) · 870 Bytes
/
search.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
package handlers
import (
"net/http"
"github.com/egnd/fb2lib/internal/entities"
"github.com/egnd/fb2lib/pkg/pagination"
"github.com/flosch/pongo2/v5"
"github.com/labstack/echo/v4"
)
func SearchHandler(repo entities.IBooksIndexRepo) echo.HandlerFunc {
return func(c echo.Context) (err error) {
searchQuery := c.QueryParam("q")
pager := pagination.NewPager(c.Request()).SetPageSize(20).
ReadPageSize().ReadCurPage()
var books []entities.BookIndex
books, err = repo.SearchAll(searchQuery, pager)
if err != nil {
c.NoContent(http.StatusBadRequest)
return
}
return c.Render(http.StatusOK, "books-list.html", pongo2.Context{
"search_query": searchQuery,
"search_placeholder": "Автор, название книги, серии, ISBN и т.д.",
"search_type": "all",
"books": books,
"pager": pager,
})
}
}