aboutsummaryrefslogblamecommitdiff
path: root/pkg/handler/random.go
blob: 091058f262123537e5a641674ffb32bff0ddfe7d (plain) (tree)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
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())
}