From e849e705c30cceec3cf7336a21bed96c8a911e90 Mon Sep 17 00:00:00 2001 From: Alexander Neonxp Kiryukhin Date: Tue, 8 Oct 2024 03:43:08 +0300 Subject: Добавил рейтинг Добавил страницу топа Добавил rss/xml/json feed MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pkg/handler/quote/index.go | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 pkg/handler/quote/index.go (limited to 'pkg/handler/quote/index.go') diff --git a/pkg/handler/quote/index.go b/pkg/handler/quote/index.go new file mode 100644 index 0000000..9dd21f8 --- /dev/null +++ b/pkg/handler/quote/index.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) Index(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("id 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()) +} -- cgit v1.2.3