Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(api-gql): use service for roles #790

Merged
merged 4 commits into from
Dec 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 16 additions & 5 deletions apps/api-gql/cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ import (
"github.com/twirapp/twir/apps/api-gql/internal/services/greetings"
"github.com/twirapp/twir/apps/api-gql/internal/services/keywords"
"github.com/twirapp/twir/apps/api-gql/internal/services/roles"
"github.com/twirapp/twir/apps/api-gql/internal/services/roles_users"
"github.com/twirapp/twir/apps/api-gql/internal/services/roles_with_roles_users"
"github.com/twirapp/twir/apps/api-gql/internal/services/timers"
"github.com/twirapp/twir/apps/api-gql/internal/services/twir-users"
"github.com/twirapp/twir/apps/api-gql/internal/services/twitch-channels"
Expand Down Expand Up @@ -71,8 +73,8 @@ import (
alertsrepository "github.com/twirapp/twir/libs/repositories/alerts"
alertsrepositorypgx "github.com/twirapp/twir/libs/repositories/alerts/pgx"

commandswithgroupsandreponsesrepository "github.com/twirapp/twir/libs/repositories/commands_with_groups_and_responses"
commandswithgroupsandreponsesrepositorypgx "github.com/twirapp/twir/libs/repositories/commands_with_groups_and_responses/pgx"
commandswithgroupsandresponsesrepository "github.com/twirapp/twir/libs/repositories/commands_with_groups_and_responses"
commandswithgroupsandresponsesrepositorypgx "github.com/twirapp/twir/libs/repositories/commands_with_groups_and_responses/pgx"

commandsgroupsrepository "github.com/twirapp/twir/libs/repositories/commands_group"
commandsgroupsrepositorypgx "github.com/twirapp/twir/libs/repositories/commands_group/pgx"
Expand All @@ -86,6 +88,9 @@ import (
rolesrepository "github.com/twirapp/twir/libs/repositories/roles"
rolesrepositorypgx "github.com/twirapp/twir/libs/repositories/roles/pgx"

rolesusersrepository "github.com/twirapp/twir/libs/repositories/roles_users"
rolesusersrepositorypgx "github.com/twirapp/twir/libs/repositories/roles_users/pgx"

greetingsrepository "github.com/twirapp/twir/libs/repositories/greetings"
greetingsrepositorypgx "github.com/twirapp/twir/libs/repositories/greetings/pgx"
)
Expand Down Expand Up @@ -119,8 +124,10 @@ func main() {
commands_groups.New,
commands_responses.New,
commands.New,
roles.New,
greetings.New,
roles.New,
roles_users.New,
roles_with_roles_users.New,
),
// repositories
fx.Provide(
Expand Down Expand Up @@ -161,8 +168,8 @@ func main() {
fx.As(new(alertsrepository.Repository)),
),
fx.Annotate(
commandswithgroupsandreponsesrepositorypgx.NewFx,
fx.As(new(commandswithgroupsandreponsesrepository.Repository)),
commandswithgroupsandresponsesrepositorypgx.NewFx,
fx.As(new(commandswithgroupsandresponsesrepository.Repository)),
),
fx.Annotate(
commandsgroupsrepositorypgx.NewFx,
Expand All @@ -180,6 +187,10 @@ func main() {
rolesrepositorypgx.NewFx,
fx.As(new(rolesrepository.Repository)),
),
fx.Annotate(
rolesusersrepositorypgx.NewFx,
fx.As(new(rolesusersrepository.Repository)),
),
fx.Annotate(
greetingsrepositorypgx.NewFx,
fx.As(new(greetingsrepository.Repository)),
Expand Down
26 changes: 26 additions & 0 deletions apps/api-gql/internal/delivery/gql/mappers/roles.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package mappers

import (
"github.com/twirapp/twir/apps/api-gql/internal/delivery/gql/gqlmodel"
"github.com/twirapp/twir/apps/api-gql/internal/entity"
)

func RolesToGql(m entity.ChannelRole) gqlmodel.Role {
permissions := make([]gqlmodel.ChannelRolePermissionEnum, len(m.Permissions))
for i, permission := range m.Permissions {
permissions[i] = gqlmodel.ChannelRolePermissionEnum(permission)
}

return gqlmodel.Role{
ID: m.ID,
ChannelID: m.ChannelID,
Name: m.Name,
Type: gqlmodel.RoleTypeEnum(m.Type.String()),
Permissions: permissions,
Settings: &gqlmodel.RoleSettings{
RequiredWatchTime: int(m.RequiredWatchTime),
RequiredMessages: int(m.RequiredMessages),
RequiredUserChannelPoints: int(m.RequiredUsedChannelPoints),
},
}
}
31 changes: 6 additions & 25 deletions apps/api-gql/internal/delivery/gql/resolvers/commands.resolver.go

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

16 changes: 3 additions & 13 deletions apps/api-gql/internal/delivery/gql/resolvers/greetings.resolver.go

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

16 changes: 12 additions & 4 deletions apps/api-gql/internal/delivery/gql/resolvers/resolver.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ import (
"github.com/twirapp/twir/apps/api-gql/internal/services/greetings"
"github.com/twirapp/twir/apps/api-gql/internal/services/keywords"
"github.com/twirapp/twir/apps/api-gql/internal/services/roles"
"github.com/twirapp/twir/apps/api-gql/internal/services/roles_users"
"github.com/twirapp/twir/apps/api-gql/internal/services/roles_with_roles_users"
"github.com/twirapp/twir/apps/api-gql/internal/services/timers"
twir_users "github.com/twirapp/twir/apps/api-gql/internal/services/twir-users"
"github.com/twirapp/twir/apps/api-gql/internal/services/users"
Expand Down Expand Up @@ -71,8 +73,10 @@ type Resolver struct {
commandsService *commands.Service
commandsWithGroupsAndResponsesService *commands_with_groups_and_responses.Service
commandsResponsesService *commands_responses.Service
rolesService *roles.Service
greetingsService *greetings.Service
rolesService *roles.Service
rolesUsersService *roles_users.Service
rolesWithUsersService *roles_with_roles_users.Service
}

type Opts struct {
Expand Down Expand Up @@ -105,8 +109,10 @@ type Opts struct {
CommandsService *commands.Service
CommandsWithGroupsAndResponsesService *commands_with_groups_and_responses.Service
CommandsResponsesService *commands_responses.Service
RolesService *roles.Service
GreetingsService *greetings.Service
RolesService *roles.Service
RolesUsersService *roles_users.Service
RolesWithUsersService *roles_with_roles_users.Service
}

func New(opts Opts) (*Resolver, error) {
Expand All @@ -121,11 +127,11 @@ func New(opts Opts) (*Resolver, error) {
gorm: opts.Gorm,
twitchClient: twitchClient,
cachedTwitchClient: opts.CachedTwitchClient,
cachedCommandsClient: opts.CachedCommandsClient,
minioClient: opts.Minio,
twirBus: opts.TwirBus,
logger: opts.Logger,
redis: opts.Redis,
cachedCommandsClient: opts.CachedCommandsClient,
tokensClient: opts.TokensGrpc,
wsRouter: opts.WsRouter,
twirStats: opts.TwirStats,
Expand All @@ -143,8 +149,10 @@ func New(opts Opts) (*Resolver, error) {
commandsService: opts.CommandsService,
commandsWithGroupsAndResponsesService: opts.CommandsWithGroupsAndResponsesService,
commandsResponsesService: opts.CommandsResponsesService,
rolesService: opts.RolesService,
greetingsService: opts.GreetingsService,
rolesService: opts.RolesService,
rolesUsersService: opts.RolesUsersService,
rolesWithUsersService: opts.RolesWithUsersService,
}, nil
}

Expand Down
Loading
Loading