Skip to content

Commit

Permalink
Restore category column
Browse files Browse the repository at this point in the history
  • Loading branch information
aopoltorzhicky committed Jan 7, 2025
1 parent 3a12ad4 commit fce45bd
Show file tree
Hide file tree
Showing 21 changed files with 417 additions and 67 deletions.
34 changes: 34 additions & 0 deletions cmd/api/docs/swagger.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 10 additions & 6 deletions cmd/api/handler/constant.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,18 @@ import (
type ConstantHandler struct {
constants storage.IConstant
denomMetadata storage.IDenomMetadata
address storage.IAddress
rollup storage.IRollup
}

func NewConstantHandler(
constants storage.IConstant,
denomMetadata storage.IDenomMetadata,
address storage.IAddress,
rollup storage.IRollup,
) *ConstantHandler {
return &ConstantHandler{
constants: constants,
denomMetadata: denomMetadata,
address: address,
rollup: rollup,
}
}

Expand All @@ -43,11 +43,11 @@ func NewConstantHandler(
func (handler *ConstantHandler) Get(c echo.Context) error {
consts, err := handler.constants.All(c.Request().Context())
if err != nil {
return handleError(c, err, handler.address)
return handleError(c, err, handler.rollup)
}
dm, err := handler.denomMetadata.All(c.Request().Context())
if err != nil {
return handleError(c, err, handler.address)
return handleError(c, err, handler.rollup)
}
return c.JSON(http.StatusOK, responses.NewConstants(consts, dm))
}
Expand All @@ -62,5 +62,9 @@ func (handler *ConstantHandler) Get(c echo.Context) error {
// @Success 200 {object} responses.Enums
// @Router /enums [get]
func (handler *ConstantHandler) Enums(c echo.Context) error {
return c.JSON(http.StatusOK, responses.NewEnums())
tags, err := handler.rollup.Tags(c.Request().Context())
if err != nil {
return handleError(c, err, handler.rollup)
}
return c.JSON(http.StatusOK, responses.NewEnums(tags))
}
12 changes: 10 additions & 2 deletions cmd/api/handler/constant_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ type ConstantTestSuite struct {
suite.Suite
constants *mock.MockIConstant
denomMetadata *mock.MockIDenomMetadata
address *mock.MockIAddress
rollup *mock.MockIRollup
echo *echo.Echo
handler *ConstantHandler
ctrl *gomock.Controller
Expand All @@ -35,7 +35,8 @@ func (s *ConstantTestSuite) SetupSuite() {
s.ctrl = gomock.NewController(s.T())
s.constants = mock.NewMockIConstant(s.ctrl)
s.denomMetadata = mock.NewMockIDenomMetadata(s.ctrl)
s.address = mock.NewMockIAddress(s.ctrl)
s.rollup = mock.NewMockIRollup(s.ctrl)
s.handler = NewConstantHandler(s.constants, s.denomMetadata, s.rollup)
}

// TearDownSuite -
Expand All @@ -54,6 +55,11 @@ func (s *ConstantTestSuite) TestEnums() {
c := s.echo.NewContext(req, rec)
c.SetPath("/enums")

s.rollup.EXPECT().
Tags(gomock.Any()).
Return([]string{"ai", "zk"}, nil).
Times(1)

s.Require().NoError(s.handler.Enums(c))
s.Require().Equal(http.StatusOK, rec.Code)

Expand All @@ -63,4 +69,6 @@ func (s *ConstantTestSuite) TestEnums() {
s.Require().Len(enums.EventType, 59)
s.Require().Len(enums.MessageType, 76)
s.Require().Len(enums.Status, 2)
s.Require().Len(enums.Categories, 5)
s.Require().Len(enums.Tags, 2)
}
6 changes: 5 additions & 1 deletion cmd/api/handler/responses/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,14 +69,18 @@ type Enums struct {
Status []string `json:"status"`
MessageType []string `json:"message_type"`
EventType []string `json:"event_type"`
Categories []string `json:"categories"`
RollupTypes []string `json:"rollup_type"`
Tags []string `json:"tags"`
}

func NewEnums() Enums {
func NewEnums(tags []string) Enums {
return Enums{
Status: types.StatusNames(),
MessageType: types.MsgTypeNames(),
EventType: types.EventTypeNames(),
Categories: types.RollupCategoryNames(),
RollupTypes: types.RollupTypeNames(),
Tags: tags,
}
}
5 changes: 5 additions & 0 deletions cmd/api/handler/responses/rollup.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ func NewRollupWithStats(r storage.RollupWithStats) RollupWithStats {
LastAction: r.LastActionTime,
FirstAction: r.FirstActionTime,
Compression: r.Compression,
Category: r.Category.String(),
Type: r.Type.String(),
Provider: r.Provider,
VM: r.VM,
Expand All @@ -90,6 +91,7 @@ type Rollup struct {
BridgeContract string `example:"https://github.com/account" format:"string" json:"bridge,omitempty" swaggertype:"string"`
Stack string `example:"op_stack" format:"string" json:"stack,omitempty" swaggertype:"string"`
Type string `example:"settled" format:"string" json:"type,omitempty" swaggertype:"string"`
Category string `example:"nft" format:"string" json:"category,omitempty" swaggertype:"string"`
Provider string `example:"name" format:"string" json:"provider,omitempty" swaggertype:"string"`
Compression string `example:"zip" format:"string" json:"compression,omitempty" swaggertype:"string"`
VM string `example:"evm" format:"string" json:"vm,omitempty" swaggertype:"string"`
Expand All @@ -115,6 +117,7 @@ func NewRollup(r *storage.Rollup) Rollup {
Explorer: r.Explorer,
Links: r.Links,
Compression: r.Compression,
Category: r.Category.String(),
Type: r.Type.String(),
Provider: r.Provider,
VM: r.VM,
Expand Down Expand Up @@ -156,6 +159,7 @@ type RollupWithDayStats struct {
BridgeContract string `example:"https://github.com/account" format:"string" json:"bridge,omitempty" swaggertype:"string"`
Stack string `example:"op_stack" format:"string" json:"stack,omitempty" swaggertype:"string"`
Type string `example:"settled" format:"string" json:"type,omitempty" swaggertype:"string"`
Category string `example:"nft" format:"string" json:"category,omitempty" swaggertype:"string"`
Provider string `example:"name" format:"string" json:"provider,omitempty" swaggertype:"string"`
Compression string `example:"zip" format:"string" json:"compression,omitempty" swaggertype:"string"`
VM string `example:"evm" format:"string" json:"vm,omitempty" swaggertype:"string"`
Expand Down Expand Up @@ -187,6 +191,7 @@ func NewRollupWithDayStats(r storage.RollupWithDayStats) RollupWithDayStats {
BridgeContract: r.BridgeContract,
Stack: r.Stack,
Compression: r.Compression,
Category: r.Category.String(),
Type: r.Type.String(),
Provider: r.Provider,
VM: r.VM,
Expand Down
40 changes: 28 additions & 12 deletions cmd/api/handler/rollup.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,13 @@ func NewRollupHandler(
}

type rollupList struct {
Limit int `query:"limit" validate:"omitempty,min=1,max=100"`
Offset int `query:"offset" validate:"omitempty,min=0"`
Sort string `query:"sort" validate:"omitempty,oneof=asc desc"`
SortBy string `query:"sort_by" validate:"omitempty,oneof=time blobs_count size fee"`
Tags StringArray `query:"tags" validate:"omitempty"`
Type StringArray `query:"type" validate:"omitempty,dive,type"`
Limit int `query:"limit" validate:"omitempty,min=1,max=100"`
Offset int `query:"offset" validate:"omitempty,min=0"`
Sort string `query:"sort" validate:"omitempty,oneof=asc desc"`
SortBy string `query:"sort_by" validate:"omitempty,oneof=time blobs_count size fee"`
Tags StringArray `query:"tags" validate:"omitempty"`
Category StringArray `query:"category" validate:"omitempty,dive,category"`
Type StringArray `query:"type" validate:"omitempty,dive,type"`
}

func (p *rollupList) SetDefault() {
Expand All @@ -64,6 +65,7 @@ func (p *rollupList) SetDefault() {
// @Param sort query string false "Sort order. Default: desc" Enums(asc, desc)
// @Param sort_by query string false "Sort field. Default: size" Enums(time, blobs_count, size, fee)
// @Param category query string false "Comma-separated rollup category list"
// @Param tags query string false "Comma-separated rollup tags list"
// @Produce json
// @Success 200 {array} responses.RollupWithStats
// @Failure 400 {object} Error
Expand All @@ -81,11 +83,17 @@ func (handler RollupHandler) Leaderboard(c echo.Context) error {
rollupTypes[i] = types.RollupType(req.Type[i])
}

categories := make([]types.RollupCategory, len(req.Category))
for i := range categories {
categories[i] = types.RollupCategory(req.Category[i])
}

rollups, err := handler.rollups.Leaderboard(c.Request().Context(), storage.LeaderboardFilters{
SortField: req.SortBy,
Sort: pgSort(req.Sort),
Limit: req.Limit,
Offset: req.Offset,
Category: categories,
Tags: req.Tags,
Type: rollupTypes,
})
Expand All @@ -100,12 +108,13 @@ func (handler RollupHandler) Leaderboard(c echo.Context) error {
}

type rollupDayList struct {
Limit int `query:"limit" validate:"omitempty,min=1,max=100"`
Offset int `query:"offset" validate:"omitempty,min=0"`
Sort string `query:"sort" validate:"omitempty,oneof=asc desc"`
SortBy string `query:"sort_by" validate:"omitempty,oneof=avg_size blobs_count total_size total_fee throughput namespace_count pfb_count mb_price"`
Tags StringArray `query:"tags" validate:"omitempty"`
Type StringArray `query:"type" validate:"omitempty,dive,type"`
Limit int `query:"limit" validate:"omitempty,min=1,max=100"`
Offset int `query:"offset" validate:"omitempty,min=0"`
Sort string `query:"sort" validate:"omitempty,oneof=asc desc"`
SortBy string `query:"sort_by" validate:"omitempty,oneof=avg_size blobs_count total_size total_fee throughput namespace_count pfb_count mb_price"`
Category StringArray `query:"category" validate:"omitempty,dive,category"`
Tags StringArray `query:"tags" validate:"omitempty"`
Type StringArray `query:"type" validate:"omitempty,dive,type"`
}

func (p *rollupDayList) SetDefault() {
Expand All @@ -131,6 +140,7 @@ func (p *rollupDayList) SetDefault() {
// @Param sort query string false "Sort order. Default: desc" Enums(asc, desc)
// @Param sort_by query string false "Sort field. Default: mb_price" Enums(avg_size, blobs_count, total_size, total_fee, throughput, namespace_count, pfb_count, mb_price)
// @Param category query string false "Comma-separated rollup category list"
// @Param tags query string false "Comma-separated rollup tags list"
// @Produce json
// @Success 200 {array} responses.RollupWithDayStats
// @Failure 400 {object} Error
Expand All @@ -148,12 +158,18 @@ func (handler RollupHandler) LeaderboardDay(c echo.Context) error {
rollupTypes[i] = types.RollupType(req.Type[i])
}

categories := make([]types.RollupCategory, len(req.Category))
for i := range categories {
categories[i] = types.RollupCategory(req.Category[i])
}

rollups, err := handler.rollups.LeaderboardDay(c.Request().Context(), storage.LeaderboardFilters{
SortField: req.SortBy,
Sort: pgSort(req.Sort),
Limit: req.Limit,
Offset: req.Offset,
Tags: req.Tags,
Category: categories,
Type: rollupTypes,
})
if err != nil {
Expand Down
4 changes: 4 additions & 0 deletions cmd/api/handler/rollup_auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ type createRollupRequest struct {
Explorer string `json:"explorer" validate:"omitempty,url"`
Stack string `json:"stack" validate:"omitempty"`
Links []string `json:"links" validate:"omitempty,dive,url"`
Category string `json:"category" validate:"omitempty,category"`
Tags []string `json:"tags" validate:"omitempty"`
Type string `json:"type" validate:"omitempty,oneof=settled sovereign"`
Compression string `json:"compression" validate:"omitempty"`
Expand Down Expand Up @@ -99,6 +100,7 @@ func (handler RollupAuthHandler) createRollup(ctx context.Context, req *createRo
Provider: req.Provider,
VM: req.VM,
Type: enums.RollupType(req.Type),
Category: enums.RollupCategory(req.Category),
Slug: slug.Make(req.Name),
Tags: req.Tags,
}
Expand Down Expand Up @@ -165,6 +167,7 @@ type updateRollupRequest struct {
Bridge string `json:"bridge" validate:"omitempty,eth_addr"`
Explorer string `json:"explorer" validate:"omitempty,url"`
Stack string `json:"stack" validate:"omitempty"`
Category string `json:"category" validate:"omitempty,category"`
Type string `json:"type" validate:"omitempty,oneof=settled sovereign"`
Compression string `json:"compression" validate:"omitempty"`
Provider string `json:"provider" validate:"omitempty"`
Expand Down Expand Up @@ -215,6 +218,7 @@ func (handler RollupAuthHandler) updateRollup(ctx context.Context, req *updateRo
Provider: req.Provider,
VM: req.VM,
Type: enums.RollupType(req.Type),
Category: enums.RollupCategory(req.Category),
Links: req.Links,
Tags: req.Tags,
}
Expand Down
Loading

0 comments on commit fce45bd

Please sign in to comment.