Skip to content

Commit

Permalink
feat: tags collection redesign
Browse files Browse the repository at this point in the history
  • Loading branch information
haller33 committed Dec 4, 2024
1 parent d1ef6b1 commit 4654758
Show file tree
Hide file tree
Showing 10 changed files with 615 additions and 53 deletions.
10 changes: 5 additions & 5 deletions api/services/tags.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ import (
)

type TagsService interface {
GetTags(ctx context.Context, tenant string) ([]string, int, error)
GetTags(ctx context.Context, tenant string) ([]models.Tags, int, error)
RenameTag(ctx context.Context, tenant string, oldTag string, newTag string) error
DeleteTag(ctx context.Context, tenant string, tag string) error
}

func (s *service) GetTags(ctx context.Context, tenant string) ([]string, int, error) {
func (s *service) GetTags(ctx context.Context, tenant string) ([]models.Tags, int, error) {
namespace, err := s.store.NamespaceGet(ctx, tenant)
if err != nil || namespace == nil {
return nil, 0, NewErrNamespaceNotFound(tenant, err)
Expand All @@ -31,11 +31,11 @@ func (s *service) RenameTag(ctx context.Context, tenant string, oldTag string, n
return NewErrTagEmpty(tenant, err)
}

if !contains(tags, oldTag) {
if !containsTags(tags, oldTag) {
return NewErrTagNotFound(oldTag, nil)
}

if contains(tags, newTag) {
if containsTags(tags, newTag) {
return NewErrTagDuplicated(newTag, nil)
}

Expand All @@ -59,7 +59,7 @@ func (s *service) DeleteTag(ctx context.Context, tenant string, tag string) erro
return NewErrTagEmpty(tenant, err)
}

if !contains(tags, tag) {
if !containsTags(tags, tag) {
return NewErrTagNotFound(tag, nil)
}

Expand Down
11 changes: 11 additions & 0 deletions api/services/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"os"

jwt "github.com/golang-jwt/jwt/v4"
"github.com/shellhub-io/shellhub/pkg/models"
)

func LoadKeys() (*rsa.PrivateKey, *rsa.PublicKey, error) {
Expand All @@ -31,6 +32,16 @@ func LoadKeys() (*rsa.PrivateKey, *rsa.PublicKey, error) {
return privKey, pubKey, nil
}

func containsTags(list []models.Tags, item string) bool {
for _, i := range list {
if i.Name == item {
return true
}
}

return false
}

func contains(list []string, item string) bool {
for _, i := range list {
if i == item {
Expand Down
Loading

0 comments on commit 4654758

Please sign in to comment.