diff options
author | Alexander Neonxp Kiryukhin <i@neonxp.ru> | 2024-12-09 01:07:15 +0300 |
---|---|---|
committer | Alexander Neonxp Kiryukhin <i@neonxp.ru> | 2024-12-09 01:07:15 +0300 |
commit | 34ccc98a942098faefb5f4211b215ff9ccc7ad0e (patch) | |
tree | 7696ab4d7c8d9fb09c7e2575d482517f68824ae3 /pkg/api/next.go |
Начальный
Diffstat (limited to 'pkg/api/next.go')
-rw-r--r-- | pkg/api/next.go | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/pkg/api/next.go b/pkg/api/next.go new file mode 100644 index 0000000..c73af62 --- /dev/null +++ b/pkg/api/next.go @@ -0,0 +1,28 @@ +package api + +import ( + "time" + + "git.neonxp.ru/neonxp/guessr/pkg/middleware" + "github.com/labstack/echo/v4" +) + +func (h *Handler) PostNext(c echo.Context) error { + p, err := h.places.GetNext(c.Request().Context()) + if err != nil { + return err + } + + if state := c.Get("state"); state == nil { + return echo.ErrBadRequest + } + + state := c.Get("state").(*middleware.State) + state.CurrentGUID = p.GUID + state.Image = p.Img + if err := middleware.SetState(c, *state, int(365*24*time.Hour)); err != nil { + return err + } + + return c.JSON(200, state) +} |