Skip to content

Commit bc09748

Browse files
committed
refactor: use gql subscriptions and mutations for bot status and actions
1 parent c74e4ab commit bc09748

File tree

17 files changed

+647
-495
lines changed

17 files changed

+647
-495
lines changed

apps/api-gql/cmd/main.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ import (
3030
"github.com/twirapp/twir/apps/api-gql/internal/services/commands_responses"
3131
"github.com/twirapp/twir/apps/api-gql/internal/services/commands_with_groups_and_responses"
3232
"github.com/twirapp/twir/apps/api-gql/internal/services/community_redemptions"
33+
"github.com/twirapp/twir/apps/api-gql/internal/services/dashboard"
3334
"github.com/twirapp/twir/apps/api-gql/internal/services/dashboard-widget-events"
3435
"github.com/twirapp/twir/apps/api-gql/internal/services/greetings"
3536
"github.com/twirapp/twir/apps/api-gql/internal/services/keywords"
@@ -93,7 +94,6 @@ import (
9394

9495
channelscommandsprefixrepository "github.com/twirapp/twir/libs/repositories/channels_commands_prefix"
9596
channelscommandsprefixpgx "github.com/twirapp/twir/libs/repositories/channels_commands_prefix/pgx"
96-
"github.com/twirapp/twir/libs/uptrace"
9797
"go.uber.org/fx"
9898
)
9999

@@ -213,6 +213,7 @@ func main() {
213213
song_requests.New,
214214
community_redemptions.New,
215215
streamelements.New,
216+
dashboard.New,
216217
),
217218
// grpc clients
218219
fx.Provide(
@@ -247,7 +248,6 @@ func main() {
247248
),
248249
fx.Invoke(
249250
gql.New,
250-
uptrace.NewFx("api-gql"),
251251
publicroutes.New,
252252
http_webhooks.New,
253253
authroutes.New,
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package mappers
2+
3+
import (
4+
"github.com/twirapp/twir/apps/api-gql/internal/delivery/gql/gqlmodel"
5+
"github.com/twirapp/twir/apps/api-gql/internal/entity"
6+
)
7+
8+
func DashboardStatsEntityToGql(e entity.DashboardStats) gqlmodel.DashboardStats {
9+
return gqlmodel.DashboardStats{
10+
CategoryID: e.StreamCategoryID,
11+
CategoryName: e.StreamCategoryName,
12+
Viewers: e.StreamViewers,
13+
StartedAt: e.StreamStartedAt,
14+
Title: e.StreamTitle,
15+
ChatMessages: e.StreamChatMessages,
16+
Followers: e.Followers,
17+
UsedEmotes: e.UsedEmotes,
18+
RequestedSongs: e.RequestedSongs,
19+
Subs: e.Subs,
20+
}
21+
}
22+
23+
func DashboardBotInfoEntityToGql(e entity.BotStatus) gqlmodel.BotStatus {
24+
return gqlmodel.BotStatus{
25+
IsMod: e.IsMod,
26+
BotID: e.BotID,
27+
BotName: e.BotName,
28+
Enabled: e.Enabled,
29+
}
30+
}

apps/api-gql/internal/delivery/gql/resolvers/dashboard.resolver.go

+69-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

apps/api-gql/internal/delivery/gql/resolvers/dashboard.resolver.helper.go

-122
This file was deleted.

apps/api-gql/internal/delivery/gql/resolvers/resolver.go

+2
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import (
2222
"github.com/twirapp/twir/apps/api-gql/internal/services/commands_responses"
2323
"github.com/twirapp/twir/apps/api-gql/internal/services/commands_with_groups_and_responses"
2424
"github.com/twirapp/twir/apps/api-gql/internal/services/community_redemptions"
25+
"github.com/twirapp/twir/apps/api-gql/internal/services/dashboard"
2526
dashboard_widget_events "github.com/twirapp/twir/apps/api-gql/internal/services/dashboard-widget-events"
2627
"github.com/twirapp/twir/apps/api-gql/internal/services/greetings"
2728
"github.com/twirapp/twir/apps/api-gql/internal/services/keywords"
@@ -93,6 +94,7 @@ type Deps struct {
9394
SongRequestsService *song_requests.Service
9495
CommunityRedemptionsService *community_redemptions.Service
9596
StreamElementsService *streamelements.Service
97+
DashboardService *dashboard.Service
9698
Config config.Config
9799
}
98100

apps/api-gql/internal/delivery/gql/schema/dashboard.graphqls

+17
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
extend type Subscription {
22
dashboardStats: DashboardStats! @isAuthenticated
3+
botStatus: BotStatus! @isAuthenticated
4+
}
5+
6+
extend type Mutation {
7+
botJoinLeave(action: BotJoinLeaveAction!): Boolean! @isAuthenticated
38
}
49

510
type DashboardStats {
@@ -14,3 +19,15 @@ type DashboardStats {
1419
requestedSongs: Int!
1520
subs: Int!
1621
}
22+
23+
type BotStatus {
24+
isMod: Boolean!
25+
botId: String!
26+
botName: String!
27+
enabled: Boolean!
28+
}
29+
30+
enum BotJoinLeaveAction {
31+
JOIN
32+
LEAVE
33+
}
+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package entity
2+
3+
import (
4+
"time"
5+
)
6+
7+
type DashboardStats struct {
8+
StreamCategoryID string
9+
StreamCategoryName string
10+
StreamViewers *int
11+
StreamStartedAt *time.Time
12+
StreamTitle string
13+
StreamChatMessages int
14+
Followers int
15+
UsedEmotes int
16+
RequestedSongs int
17+
Subs int
18+
}
19+
20+
type BotStatus struct {
21+
IsMod bool
22+
BotID string
23+
BotName string
24+
Enabled bool
25+
}

0 commit comments

Comments
 (0)