Skip to content

Commit

Permalink
refactor(api-gql): use service for admin users (#784)
Browse files Browse the repository at this point in the history
* refactor(api-gql): use users service and repository

* finish

* upd
  • Loading branch information
Satont authored Dec 16, 2024
1 parent d51552a commit a3b4a2e
Show file tree
Hide file tree
Showing 22 changed files with 891 additions and 133 deletions.
24 changes: 23 additions & 1 deletion apps/api-gql/cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ import (
dashboard_widget_events "github.com/twirapp/twir/apps/api-gql/internal/services/dashboard-widget-events"
"github.com/twirapp/twir/apps/api-gql/internal/services/keywords"
"github.com/twirapp/twir/apps/api-gql/internal/services/timers"
twir_users "github.com/twirapp/twir/apps/api-gql/internal/services/twir-users"
twitch_channels "github.com/twirapp/twir/apps/api-gql/internal/services/twitch-channels"
"github.com/twirapp/twir/apps/api-gql/internal/services/users"
"github.com/twirapp/twir/apps/api-gql/internal/services/variables"
"github.com/twirapp/twir/apps/api-gql/internal/wsrouter"
"github.com/twirapp/twir/libs/baseapp"
Expand Down Expand Up @@ -51,6 +54,12 @@ import (

badgesusersrepository "github.com/twirapp/twir/libs/repositories/badges-users"
badgesusersrepositorypgx "github.com/twirapp/twir/libs/repositories/badges-users/pgx"

usersrepository "github.com/twirapp/twir/libs/repositories/users"
usersrepositorypgx "github.com/twirapp/twir/libs/repositories/users/pgx"

userswithchannelrepository "github.com/twirapp/twir/libs/repositories/users-with-channel"
userswithchannelrepositorypgx "github.com/twirapp/twir/libs/repositories/users-with-channel/pgx"
)

func main() {
Expand All @@ -60,6 +69,9 @@ func main() {
AppName: "api-gql",
},
),
fx.Provide(
twitchcache.New,
),
// services
fx.Provide(
dashboard_widget_events.New,
Expand All @@ -71,6 +83,9 @@ func main() {
badges.New,
badges_users.New,
badges_with_users.New,
users.New,
twitch_channels.New,
twir_users.New,
),
// repositories
fx.Provide(
Expand Down Expand Up @@ -98,6 +113,14 @@ func main() {
badgesusersrepositorypgx.NewFx,
fx.As(new(badgesusersrepository.Repository)),
),
fx.Annotate(
usersrepositorypgx.NewFx,
fx.As(new(usersrepository.Repository)),
),
fx.Annotate(
userswithchannelrepositorypgx.NewFx,
fx.As(new(userswithchannelrepository.Repository)),
),
),
// grpc clients
fx.Provide(
Expand All @@ -112,7 +135,6 @@ func main() {
fx.Provide(
auth.NewSessions,
minio.New,
twitchcache.New,
commandscache.New,
keywordscacher.New,
fx.Annotate(
Expand Down
22 changes: 22 additions & 0 deletions apps/api-gql/internal/delivery/gql/mappers/user.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package mappers

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

func UserWithChannelToAdminUser(e entity.UserWithChannel) gqlmodel.TwirAdminUser {
user := gqlmodel.TwirAdminUser{
ID: e.User.ID,
IsBotAdmin: e.User.IsBotAdmin,
IsBanned: e.User.IsBanned,
APIKey: e.User.ApiKey,
}

if e.Channel != nil {
user.IsBotEnabled = e.Channel.IsEnabled
user.IsBotModerator = e.Channel.IsBotMod
}

return user
}

This file was deleted.

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

137 changes: 55 additions & 82 deletions apps/api-gql/internal/delivery/gql/resolvers/admin-users.resolver.go

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

Loading

0 comments on commit a3b4a2e

Please sign in to comment.