ShOrgRu/pkg/handler/quote/top.go
Alexander Neonxp Kiryukhin e849e705c3
Добавил рейтинг
Добавил страницу топа
Добавил rss/xml/json feed
2024-10-08 03:50:53 +03:00

29 lines
577 B
Go

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