From 0841d340887340aded8c7e511c09f6327f131356 Mon Sep 17 00:00:00 2001 From: Satont Date: Mon, 10 Jun 2024 17:55:36 +0300 Subject: [PATCH] kruto --- .../gql/resolvers/overlays.resolver.go | 26 ++++- .../resolvers/overlays.resolver.service.go | 108 ++++++++++++++++++ .../src/pages/overlays/chat/Chat.vue | 2 +- 3 files changed, 129 insertions(+), 7 deletions(-) diff --git a/apps/api-gql/internal/gql/resolvers/overlays.resolver.go b/apps/api-gql/internal/gql/resolvers/overlays.resolver.go index 12e4beff0..af0c1d50f 100644 --- a/apps/api-gql/internal/gql/resolvers/overlays.resolver.go +++ b/apps/api-gql/internal/gql/resolvers/overlays.resolver.go @@ -14,18 +14,25 @@ import ( ) // ChatOverlayUpdate is the resolver for the chatOverlayUpdate field. -func (r *mutationResolver) ChatOverlayUpdate(ctx context.Context, id string, opts gqlmodel.ChatOverlayMutateOpts) (bool, error) { +func (r *mutationResolver) ChatOverlayUpdate( + ctx context.Context, + id string, + opts gqlmodel.ChatOverlayMutateOpts, +) (bool, error) { return r.updateChatOverlay(ctx, id, opts) } // ChatOverlayCreate is the resolver for the chatOverlayCreate field. -func (r *mutationResolver) ChatOverlayCreate(ctx context.Context, opts gqlmodel.ChatOverlayMutateOpts) (bool, error) { - panic(fmt.Errorf("not implemented: ChatOverlayCreate - chatOverlayCreate")) +func (r *mutationResolver) ChatOverlayCreate( + ctx context.Context, + opts gqlmodel.ChatOverlayMutateOpts, +) (bool, error) { + return r.chatOverlayCreate(ctx, opts) } // ChatOverlayDelete is the resolver for the chatOverlayDelete field. func (r *mutationResolver) ChatOverlayDelete(ctx context.Context, id string) (bool, error) { - panic(fmt.Errorf("not implemented: ChatOverlayDelete - chatOverlayDelete")) + return r.chatOverlayDelete(ctx, id) } // ChatOverlays is the resolver for the chatOverlays field. @@ -39,7 +46,10 @@ func (r *queryResolver) ChatOverlays(ctx context.Context) ([]gqlmodel.ChatOverla } // ChatOverlaysByID is the resolver for the chatOverlaysById field. -func (r *queryResolver) ChatOverlaysByID(ctx context.Context, id string) (*gqlmodel.ChatOverlay, error) { +func (r *queryResolver) ChatOverlaysByID(ctx context.Context, id string) ( + *gqlmodel.ChatOverlay, + error, +) { dashboardId, err := r.sessions.GetSelectedDashboard(ctx) if err != nil { return nil, err @@ -49,7 +59,11 @@ func (r *queryResolver) ChatOverlaysByID(ctx context.Context, id string) (*gqlmo } // ChatOverlaySettings is the resolver for the chatOverlaySettings field. -func (r *subscriptionResolver) ChatOverlaySettings(ctx context.Context, id string, apiKey string) (<-chan *gqlmodel.ChatOverlay, error) { +func (r *subscriptionResolver) ChatOverlaySettings( + ctx context.Context, + id string, + apiKey string, +) (<-chan *gqlmodel.ChatOverlay, error) { user := model.Users{} if err := r.gorm.Where(`"apiKey" = ?`, apiKey).First(&user).Error; err != nil { return nil, fmt.Errorf("failed to get user: %w", err) diff --git a/apps/api-gql/internal/gql/resolvers/overlays.resolver.service.go b/apps/api-gql/internal/gql/resolvers/overlays.resolver.service.go index da9cc596f..4b67953d3 100644 --- a/apps/api-gql/internal/gql/resolvers/overlays.resolver.service.go +++ b/apps/api-gql/internal/gql/resolvers/overlays.resolver.service.go @@ -176,3 +176,111 @@ func (r *mutationResolver) updateChatOverlay( return true, nil } + +func (r *mutationResolver) chatOverlayCreate( + ctx context.Context, + opts gqlmodel.ChatOverlayMutateOpts, +) (bool, error) { + dashboardId, err := r.sessions.GetSelectedDashboard(ctx) + if err != nil { + return false, err + } + + entity := model.ChatOverlaySettings{ + ID: uuid.UUID{}, + ChannelID: dashboardId, + } + + if opts.MessageHideTimeout.IsSet() { + entity.MessageHideTimeout = uint32(*opts.MessageHideTimeout.Value()) + } + + if opts.MessageShowDelay.IsSet() { + entity.MessageShowDelay = uint32(*opts.MessageShowDelay.Value()) + } + + if opts.Preset.IsSet() { + entity.Preset = *opts.Preset.Value() + } + + if opts.FontSize.IsSet() { + entity.FontSize = uint32(*opts.FontSize.Value()) + } + + if opts.HideCommands.IsSet() { + entity.HideCommands = *opts.HideCommands.Value() + } + + if opts.HideBots.IsSet() { + entity.HideBots = *opts.HideBots.Value() + } + + if opts.FontFamily.IsSet() { + entity.FontFamily = *opts.FontFamily.Value() + } + + if opts.ShowBadges.IsSet() { + entity.ShowBadges = *opts.ShowBadges.Value() + } + + if opts.ShowAnnounceBadge.IsSet() { + entity.ShowAnnounceBadge = *opts.ShowAnnounceBadge.Value() + } + + if opts.TextShadowColor.IsSet() { + entity.TextShadowColor = *opts.TextShadowColor.Value() + } + + if opts.TextShadowSize.IsSet() { + entity.TextShadowSize = uint32(*opts.TextShadowSize.Value()) + } + + if opts.ChatBackgroundColor.IsSet() { + entity.ChatBackgroundColor = *opts.ChatBackgroundColor.Value() + } + + if opts.Direction.IsSet() { + entity.Direction = *opts.Direction.Value() + } + + if opts.FontWeight.IsSet() { + entity.FontWeight = uint32(*opts.FontWeight.Value()) + } + + if opts.FontStyle.IsSet() { + entity.FontStyle = *opts.FontStyle.Value() + } + + if opts.PaddingContainer.IsSet() { + entity.PaddingContainer = uint32(*opts.PaddingContainer.Value()) + } + + if opts.Animation.IsSet() { + entity.Animation = model.ChatOverlaySettingsAnimationType(*opts.Animation.Value()) + } + + if err := r.gorm. + WithContext(ctx). + Create(&entity).Error; err != nil { + return false, fmt.Errorf("failed to create chat overlay settings: %w", err) + } + + return true, nil +} + +func (r *mutationResolver) chatOverlayDelete(ctx context.Context, id string) (bool, error) { + dashboardId, err := r.sessions.GetSelectedDashboard(ctx) + if err != nil { + return false, err + } + + entity := model.ChatOverlaySettings{} + if err := r.gorm. + WithContext(ctx). + Where("channel_id = ? AND id = ?", dashboardId, id). + Delete(&entity).Error; err != nil { + return false, fmt.Errorf("failed to delete chat overlay settings: %w", err) + } + + return true, nil +} diff --git a/frontend/dashboard/src/pages/overlays/chat/Chat.vue b/frontend/dashboard/src/pages/overlays/chat/Chat.vue index cae1f32e6..ccdcabb3d 100644 --- a/frontend/dashboard/src/pages/overlays/chat/Chat.vue +++ b/frontend/dashboard/src/pages/overlays/chat/Chat.vue @@ -185,7 +185,7 @@ const addable = computed(() => { - + Create new overlay for edit settings