aboutsummaryrefslogtreecommitdiff
path: root/pkg/handler/quote.go
blob: af9fd8204c593d169a372efcdb2611388026184a (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
package handler

import (
	"strconv"

	"github.com/labstack/echo/v4"
	"sh.org.ru/pkg/model"
	"sh.org.ru/pkg/tpl"
)

func (h *Handler) Quote(c echo.Context) error {
	sid := c.Param("id")
	id, err := strconv.Atoi(sid)
	if err != nil {
		return err
	}

	quote := new(model.Quote)
	err = h.DB.NewSelect().
		Model(quote).
		Where("id = ?", id).Scan(c.Request().Context(), quote)
	if err != nil {
		return err
	}

	return tpl.QuotePage(quote).Render(c.Request().Context(), c.Response())
}