shorgru/pkg/handler/quote/random.go

19 lines
435 B
Go
Raw Normal View History

package quote
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())
}