diff options
Diffstat (limited to 'pkg/handler/quote/quote.go')
-rw-r--r-- | pkg/handler/quote/quote.go | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/pkg/handler/quote/quote.go b/pkg/handler/quote/quote.go new file mode 100644 index 0000000..b25eb90 --- /dev/null +++ b/pkg/handler/quote/quote.go @@ -0,0 +1,27 @@ +package quote + +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 echo.ErrNotFound + } + + 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()) +} |