Skip to content

Commit

Permalink
feat: items request count limit
Browse files Browse the repository at this point in the history
fix: migrations
feat: error on items request count=0
  • Loading branch information
krigga committed Aug 30, 2023
1 parent e11571e commit 7382544
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 4 deletions.
2 changes: 1 addition & 1 deletion cmd/server/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ func doMigrate() error {
}

err = m.Up()
if err != nil {
if err != nil && err != migrate.ErrNoChange {
return err
}

Expand Down
15 changes: 13 additions & 2 deletions http/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ import (
"github.com/xssnick/tonutils-go/tvm/cell"
)

const ITEMS_LIMIT = 10000

type Handler struct {
StateProvider provider.StateProvider
NodeProvider provider.NodeProvider
Expand Down Expand Up @@ -69,8 +71,8 @@ func (h *Handler) getItemsInternal(from uint64, count uint64) (*ItemsResponse, e
}

type ItemsRequest struct {
From uint64 `param:"from"`
Count uint64 `param:"count"`
From uint64 `query:"from"`
Count uint64 `query:"count"`
}

type ItemsResponse struct {
Expand All @@ -86,6 +88,15 @@ func (h *Handler) getItems(c echo.Context) error {
return c.String(http.StatusBadRequest, "bad request")
}

if ir.Count == 0 {
log.Error().Msg("items request has count set to 0")
return c.String(http.StatusBadRequest, "bad request")
}

if ir.Count > ITEMS_LIMIT {
ir.Count = ITEMS_LIMIT
}

resp, err := h.getItemsInternal(ir.From, ir.Count)
if err != nil {
log.Err(err).Msg("could not get items")
Expand Down
2 changes: 1 addition & 1 deletion http/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
func (h *Handler) RegisterHandlers(e *echo.Echo) {
v1 := e.Group("/v1")

v1.GET("/items/:from/:count", h.getItems)
v1.GET("/items", h.getItems)
v1.GET("/item/:index", h.getItem)
v1.GET("/state", h.getState)

Expand Down

0 comments on commit 7382544

Please sign in to comment.