Skip to content

Commit

Permalink
refactor(api): use service for alerts
Browse files Browse the repository at this point in the history
  • Loading branch information
Satont committed Dec 16, 2024
1 parent fb76abd commit c4b4d43
Show file tree
Hide file tree
Showing 14 changed files with 548 additions and 170 deletions.
9 changes: 9 additions & 0 deletions apps/api-gql/cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
"github.com/twirapp/twir/apps/api-gql/internal/server"
"github.com/twirapp/twir/apps/api-gql/internal/server/middlewares"
admin_actions "github.com/twirapp/twir/apps/api-gql/internal/services/admin-actions"
"github.com/twirapp/twir/apps/api-gql/internal/services/alerts"
audit_logs "github.com/twirapp/twir/apps/api-gql/internal/services/audit-logs"
"github.com/twirapp/twir/apps/api-gql/internal/services/badges"
badges_users "github.com/twirapp/twir/apps/api-gql/internal/services/badges-users"
Expand Down Expand Up @@ -60,6 +61,9 @@ import (

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

alertsrepository "github.com/twirapp/twir/libs/repositories/alerts"
alertsrepositorypgx "github.com/twirapp/twir/libs/repositories/alerts/pgx"
)

func main() {
Expand All @@ -86,6 +90,7 @@ func main() {
users.New,
twitch_channels.New,
twir_users.New,
alerts.New,
),
// repositories
fx.Provide(
Expand Down Expand Up @@ -121,6 +126,10 @@ func main() {
userswithchannelrepositorypgx.NewFx,
fx.As(new(userswithchannelrepository.Repository)),
),
fx.Annotate(
alertsrepositorypgx.NewFx,
fx.As(new(alertsrepository.Repository)),
),
),
// grpc clients
fx.Provide(
Expand Down
19 changes: 19 additions & 0 deletions apps/api-gql/internal/delivery/gql/mappers/alerts.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package mappers

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

func AlertEntityTo(e entity.Alert) gqlmodel.ChannelAlert {
return gqlmodel.ChannelAlert{
ID: e.ID,
Name: e.Name,
AudioID: e.AudioID,
AudioVolume: &e.AudioVolume,
CommandIds: e.CommandIDS,
RewardIds: e.RewardIDS,
GreetingsIds: e.GreetingsIDS,
KeywordsIds: e.KeywordsIDS,
}
}

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

203 changes: 47 additions & 156 deletions apps/api-gql/internal/delivery/gql/resolvers/alerts.resolver.go

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

4 changes: 4 additions & 0 deletions apps/api-gql/internal/delivery/gql/resolvers/resolver.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
"github.com/twirapp/twir/apps/api-gql/internal/auth"
twir_stats "github.com/twirapp/twir/apps/api-gql/internal/delivery/gql/twir-stats"
admin_actions "github.com/twirapp/twir/apps/api-gql/internal/services/admin-actions"
"github.com/twirapp/twir/apps/api-gql/internal/services/alerts"
audit_logs "github.com/twirapp/twir/apps/api-gql/internal/services/audit-logs"
"github.com/twirapp/twir/apps/api-gql/internal/services/badges"
badges_users "github.com/twirapp/twir/apps/api-gql/internal/services/badges-users"
Expand Down Expand Up @@ -61,6 +62,7 @@ type Resolver struct {
badgesUsersService *badges_users.Service
usersService *users.Service
twirUsersService *twir_users.Service
alertsService *alerts.Service
}

type Opts struct {
Expand Down Expand Up @@ -89,6 +91,7 @@ type Opts struct {
BadgesUsersService *badges_users.Service
UsersService *users.Service
TwirUsersService *twir_users.Service
AlertsService *alerts.Service
}

func New(opts Opts) (*Resolver, error) {
Expand Down Expand Up @@ -121,6 +124,7 @@ func New(opts Opts) (*Resolver, error) {
badgesUsersService: opts.BadgesUsersService,
usersService: opts.UsersService,
twirUsersService: opts.TwirUsersService,
alertsService: opts.AlertsService,
}, nil
}

Expand Down
19 changes: 19 additions & 0 deletions apps/api-gql/internal/entity/alert.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package entity

import (
"github.com/google/uuid"
)

type Alert struct {
ID uuid.UUID
Name string
ChannelID string
AudioID *string
AudioVolume int
CommandIDS []string
RewardIDS []string
GreetingsIDS []string
KeywordsIDS []string
}

var AlertNil = Alert{}
Loading

0 comments on commit c4b4d43

Please sign in to comment.