2024-10-08 03:43:08 +03:00
|
|
|
package quote
|
2024-10-06 17:04:37 +03:00
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/labstack/echo/v4"
|
|
|
|
"sh.org.ru/pkg/model"
|
|
|
|
"sh.org.ru/pkg/tpl"
|
|
|
|
)
|
|
|
|
|
2024-10-08 03:43:08 +03:00
|
|
|
func (h *Handler) Top(c echo.Context) error {
|
2024-10-06 17:04:37 +03:00
|
|
|
p := &Pagination{}
|
|
|
|
if err := c.Bind(p); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
quotes := make([]model.Quote, 0, 20)
|
2024-10-08 03:43:08 +03:00
|
|
|
count, err := h.db.NewSelect().
|
2024-10-06 17:04:37 +03:00
|
|
|
Model((*model.Quote)(nil)).
|
2024-10-08 03:43:08 +03:00
|
|
|
Order("rating DESC").
|
2024-10-06 17:04:37 +03:00
|
|
|
Where("approved = ?", true).
|
|
|
|
Limit(20).
|
|
|
|
Offset(p.Page*20).
|
|
|
|
ScanAndCount(c.Request().Context(), "es)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2024-10-08 03:43:08 +03:00
|
|
|
return tpl.List(quotes, p.Page, count).Render(c.Request().Context(), c.Response())
|
2024-10-06 17:04:37 +03:00
|
|
|
}
|