Skip to content

Commit

Permalink
sorting
Browse files Browse the repository at this point in the history
  • Loading branch information
Satont committed Dec 19, 2024
1 parent 559f905 commit a57abb7
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 8 deletions.
8 changes: 8 additions & 0 deletions apps/api-gql/internal/entity/role.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,14 @@ const (
ChannelRoleTypeCustom ChannelRoleEnum = "CUSTOM"
)

var AllChannelRoleTypeEnum = []ChannelRoleEnum{
ChannelRoleTypeBroadcaster,
ChannelRoleTypeModerator,
ChannelRoleTypeSubscriber,
ChannelRoleTypeVip,
ChannelRoleTypeCustom,
}

type ChannelRoleUser struct {
ID uuid.UUID
UserID string
Expand Down
17 changes: 9 additions & 8 deletions apps/api-gql/internal/services/roles/roles.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package roles
import (
"context"
"fmt"
"slices"

"github.com/google/uuid"
"github.com/samber/lo"
Expand Down Expand Up @@ -82,14 +83,14 @@ func (c *Service) GetManyByChannelID(ctx context.Context, channelID string) (
entities = append(entities, c.modelToEntity(dbRole))
}

// slices.SortFunc(
// entities,
// func(a, b entity.ChannelRole) int {
// typeIdx := lo.IndexOf(gqlmodel.AllRoleTypeEnum, a.Type)
//
// return typeIdx - lo.IndexOf(gqlmodel.AllRoleTypeEnum, b.Type)
// },
// )
slices.SortFunc(
entities,
func(a, b entity.ChannelRole) int {
typeIdx := lo.IndexOf(entity.AllChannelRoleTypeEnum, a.Type)

return typeIdx - lo.IndexOf(entity.AllChannelRoleTypeEnum, b.Type)
},
)

return entities, nil
}
Expand Down

0 comments on commit a57abb7

Please sign in to comment.