diff options
Diffstat (limited to 'pkg/handler/quote/top.go')
-rw-r--r-- | pkg/handler/quote/top.go | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/pkg/handler/quote/top.go b/pkg/handler/quote/top.go new file mode 100644 index 0000000..c2803ea --- /dev/null +++ b/pkg/handler/quote/top.go @@ -0,0 +1,28 @@ +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(), "es) + if err != nil { + return err + } + + return tpl.List(quotes, p.Page, count).Render(c.Request().Context(), c.Response()) +} |