aboutsummaryrefslogtreecommitdiff
path: root/pkg/handler/quote/index.go
diff options
context:
space:
mode:
authorAlexander Neonxp Kiryukhin <i@neonxp.ru>2024-10-08 03:43:08 +0300
committerAlexander Neonxp Kiryukhin <i@neonxp.ru>2024-10-08 03:50:53 +0300
commite849e705c30cceec3cf7336a21bed96c8a911e90 (patch)
tree93f559bcd4cf3e53193930d112e564a2b7462ac8 /pkg/handler/quote/index.go
parent3ee654f6fb3cdf119630bfba8066c96ec26428c3 (diff)
Добавил рейтинг
Добавил страницу топа Добавил rss/xml/json feed
Diffstat (limited to 'pkg/handler/quote/index.go')
-rw-r--r--pkg/handler/quote/index.go28
1 files changed, 28 insertions, 0 deletions
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(), &quotes)
+ if err != nil {
+ return err
+ }
+
+ return tpl.List(quotes, p.Page, count).Render(c.Request().Context(), c.Response())
+}