From 6badb6adb6b60367f15432ab331b717d4a96801b Mon Sep 17 00:00:00 2001 From: H1rono Date: Fri, 7 Jun 2024 22:34:09 +0900 Subject: [PATCH] :sparkles: Impl query parameter `offset` --- router/transaction.go | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/router/transaction.go b/router/transaction.go index e7068073..36f760dc 100644 --- a/router/transaction.go +++ b/router/transaction.go @@ -85,6 +85,19 @@ func (h Handlers) GetTransactions(c echo.Context) error { } limit = limitI } + offset := 0 + if offsetQuery := c.QueryParam("offset"); offsetQuery != "" { + offsetI, err := strconv.Atoi(offsetQuery) + if err != nil { + h.Logger.Info("could not parse limit as integer", zap.Error(err)) + return echo.NewHTTPError(http.StatusBadRequest, err) + } + if offsetI < 0 { + h.Logger.Info("received negative offset", zap.Int("offset", offsetI)) + return echo.NewHTTPError(http.StatusBadRequest, fmt.Errorf("negative offset(=%d) is invalid", offsetI)) + } + offset = offsetI + } var tag *string if c.QueryParam("tag") != "" { t := c.QueryParam("tag") @@ -111,6 +124,7 @@ func (h Handlers) GetTransactions(c echo.Context) error { Since: since, Until: until, Limit: limit, + Offset: offset, Tag: tag, Group: group, Request: request,