aboutsummaryrefslogtreecommitdiff
path: root/pkg/handler/random.go
diff options
context:
space:
mode:
Diffstat (limited to 'pkg/handler/random.go')
-rw-r--r--pkg/handler/random.go18
1 files changed, 18 insertions, 0 deletions
diff --git a/pkg/handler/random.go b/pkg/handler/random.go
new file mode 100644
index 0000000..091058f
--- /dev/null
+++ b/pkg/handler/random.go
@@ -0,0 +1,18 @@
+package handler
+
+import (
+ "github.com/labstack/echo/v4"
+ "sh.org.ru/pkg/model"
+ "sh.org.ru/pkg/tpl"
+)
+
+func (h *Handler) Random(c echo.Context) error {
+ quotes := make([]model.Quote, 0, 20)
+ err := h.DB.NewRaw(`select q.* from quotes q where q.approved = true order by random() limit 20`).
+ Scan(c.Request().Context(), &quotes)
+ if err != nil {
+ return err
+ }
+
+ return tpl.Random(quotes).Render(c.Request().Context(), c.Response())
+}