From 6c0b40f0ce81d27932421ee33f135c07e275de68 Mon Sep 17 00:00:00 2001 From: Artem Poltorzhitskiy Date: Mon, 4 Nov 2024 15:07:04 +0100 Subject: [PATCH] Feature: add social category (#300) * Feature: add social category * Fix: tests * Fix: auth endpoints validation --- cmd/api/handler/constant_test.go | 2 +- cmd/api/handler/rollup_auth.go | 4 +-- .../20241104_add_social_category.go | 25 +++++++++++++++++++ internal/storage/types/rolllup.go | 3 ++- internal/storage/types/rolllup_enum.go | 5 ++++ 5 files changed, 35 insertions(+), 4 deletions(-) create mode 100644 internal/storage/postgres/migrations/20241104_add_social_category.go diff --git a/cmd/api/handler/constant_test.go b/cmd/api/handler/constant_test.go index a2094cf8..1103e03b 100644 --- a/cmd/api/handler/constant_test.go +++ b/cmd/api/handler/constant_test.go @@ -63,5 +63,5 @@ 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, 4) + s.Require().Len(enums.Categories, 5) } diff --git a/cmd/api/handler/rollup_auth.go b/cmd/api/handler/rollup_auth.go index df7748d7..9f3281b6 100644 --- a/cmd/api/handler/rollup_auth.go +++ b/cmd/api/handler/rollup_auth.go @@ -49,7 +49,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,oneof=nft gaming finance uncategorized"` + Category string `json:"category" validate:"omitempty,category"` Type string `json:"type" validate:"omitempty,oneof=settled sovereign"` Compression string `json:"compression" validate:"omitempty"` VM string `json:"vm" validate:"omitempty"` @@ -162,7 +162,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,oneof=nft gaming finance uncategorized"` + 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"` diff --git a/internal/storage/postgres/migrations/20241104_add_social_category.go b/internal/storage/postgres/migrations/20241104_add_social_category.go new file mode 100644 index 00000000..a4f13d61 --- /dev/null +++ b/internal/storage/postgres/migrations/20241104_add_social_category.go @@ -0,0 +1,25 @@ +// SPDX-FileCopyrightText: 2024 PK Lab AG +// SPDX-License-Identifier: MIT + +package migrations + +import ( + "context" + + "github.com/uptrace/bun" +) + +func init() { + Migrations.MustRegister(upSocialCategory, downSocialCategory) +} + +func upSocialCategory(ctx context.Context, db *bun.DB) error { + if _, err := db.ExecContext(ctx, `ALTER TYPE rollup_category ADD VALUE IF NOT EXISTS 'social' AFTER 'nft'`); err != nil { + return err + } + return nil +} + +func downSocialCategory(_ context.Context, _ *bun.DB) error { + return nil +} diff --git a/internal/storage/types/rolllup.go b/internal/storage/types/rolllup.go index 606b2078..8ffda256 100644 --- a/internal/storage/types/rolllup.go +++ b/internal/storage/types/rolllup.go @@ -9,7 +9,8 @@ package types uncategorized, finance, gaming, - nft + nft, + social ) */ //go:generate go-enum --marshal --sql --values --names diff --git a/internal/storage/types/rolllup_enum.go b/internal/storage/types/rolllup_enum.go index 8c3c05af..cd98cabf 100644 --- a/internal/storage/types/rolllup_enum.go +++ b/internal/storage/types/rolllup_enum.go @@ -25,6 +25,8 @@ const ( RollupCategoryGaming RollupCategory = "gaming" // RollupCategoryNft is a RollupCategory of type nft. RollupCategoryNft RollupCategory = "nft" + // RollupCategorySocial is a RollupCategory of type social. + RollupCategorySocial RollupCategory = "social" ) var ErrInvalidRollupCategory = fmt.Errorf("not a valid RollupCategory, try [%s]", strings.Join(_RollupCategoryNames, ", ")) @@ -34,6 +36,7 @@ var _RollupCategoryNames = []string{ string(RollupCategoryFinance), string(RollupCategoryGaming), string(RollupCategoryNft), + string(RollupCategorySocial), } // RollupCategoryNames returns a list of possible string values of RollupCategory. @@ -50,6 +53,7 @@ func RollupCategoryValues() []RollupCategory { RollupCategoryFinance, RollupCategoryGaming, RollupCategoryNft, + RollupCategorySocial, } } @@ -70,6 +74,7 @@ var _RollupCategoryValue = map[string]RollupCategory{ "finance": RollupCategoryFinance, "gaming": RollupCategoryGaming, "nft": RollupCategoryNft, + "social": RollupCategorySocial, } // ParseRollupCategory attempts to convert a string to a RollupCategory.