diff --git a/server/e2e/gql_storytelling_test.go b/server/e2e/gql_storytelling_test.go index a6fab1d602..c6ffa2d4eb 100644 --- a/server/e2e/gql_storytelling_test.go +++ b/server/e2e/gql_storytelling_test.go @@ -116,6 +116,7 @@ func fetchSceneForStories(e *httpexpect.Expect, sID string) (GraphQLRequest, *ht } } } + bgColor } __typename } @@ -180,11 +181,12 @@ func createStory(e *httpexpect.Expect, sID, name string, index int) (GraphQLRequ func updateStory(e *httpexpect.Expect, storyID, sID string) (GraphQLRequest, *httpexpect.Value) { requestBody := GraphQLRequest{ OperationName: "UpdateStory", - Query: `mutation UpdateStory($sceneId: ID!, $storyId: ID!, $title: String!, $index: Int) { - updateStory( input: {sceneId: $sceneId, storyId: $storyId, title: $title, index: $index} ) { + Query: `mutation UpdateStory($sceneId: ID!, $storyId: ID!, $title: String!, $index: Int, $bgColor: String) { + updateStory( input: {sceneId: $sceneId, storyId: $storyId, title: $title, index: $index, bgColor: $bgColor} ) { story { id title + bgColor __typename } __typename @@ -195,6 +197,7 @@ func updateStory(e *httpexpect.Expect, storyID, sID string) (GraphQLRequest, *ht "sceneId": sID, "title": "test2", "index": 0, + "bgColor": "newBG", }, } @@ -780,6 +783,14 @@ func TestStoryCRUD(t *testing.T) { // update story _, _ = updateStory(e, storyID, sID) + // fetch scene and check story + _, res = fetchSceneForStories(e, sID) + storiesRes = res.Object(). + Value("data").Object(). + Value("node").Object(). + Value("stories").Array() + storiesRes.First().Object().ValueEqual("bgColor", "newBG") + _, _ = deleteStory(e, storyID, sID) } @@ -1037,7 +1048,7 @@ func TestStoryPublishing(t *testing.T) { _, err = buf.ReadFrom(rc) assert.NoError(t, err) - pub := regexp.MustCompile(fmt.Sprintf(`{"schemaVersion":1,"id":"%s","publishedAt":".*","property":{"tiles":\[{"id":".*"}]},"plugins":{},"layers":null,"widgets":\[],"widgetAlignSystem":null,"tags":\[],"clusters":\[],"story":{"id":"%s","property":{},"pages":\[{"id":"%s","property":{},"blocks":\[{"id":"%s","property":{"default":{"text":"test value"},"panel":{"padding":{"top":2,"bottom":3,"left":0,"right":1}}},"plugins":null,"extensionId":"%s","pluginId":"%s"}],"swipeable":true,"swipeableLayers":\[],"layers":\[]}]},"nlsLayers":null,"layerStyles":null,"coreSupport":true}`, sID, storyID, pageID, blockID, extensionId, pluginId)) + pub := regexp.MustCompile(fmt.Sprintf(`{"schemaVersion":1,"id":"%s","publishedAt":".*","property":{"tiles":\[{"id":".*"}]},"plugins":{},"layers":null,"widgets":\[],"widgetAlignSystem":null,"tags":\[],"clusters":\[],"story":{"id":"%s","property":{},"pages":\[{"id":"%s","property":{},"title":"test","blocks":\[{"id":"%s","property":{"default":{"text":"test value"},"panel":{"padding":{"top":2,"bottom":3,"left":0,"right":1}}},"plugins":null,"extensionId":"%s","pluginId":"%s"}],"swipeable":true,"swipeableLayers":\[],"layers":\[]}],"position":"left","bgColor":""},"nlsLayers":null,"layerStyles":null,"coreSupport":true}`, sID, storyID, pageID, blockID, extensionId, pluginId)) assert.Regexp(t, pub, buf.String()) resString := e.GET("/p/test-alias/data.json"). diff --git a/server/gql/storytelling.graphql b/server/gql/storytelling.graphql index 2671930201..a5bc71c2ab 100644 --- a/server/gql/storytelling.graphql +++ b/server/gql/storytelling.graphql @@ -12,6 +12,7 @@ type Story implements Node { sceneId: ID! scene: Scene panelPosition: Position! + bgColor: String isBasicAuthActive: Boolean! basicAuthUsername: String! @@ -68,6 +69,7 @@ input UpdateStoryInput { title: String index: Int panelPosition: Position + bgColor: String # publishment isBasicAuthActive: Boolean diff --git a/server/internal/adapter/gql/generated.go b/server/internal/adapter/gql/generated.go index e12083b850..9c933cb066 100644 --- a/server/internal/adapter/gql/generated.go +++ b/server/internal/adapter/gql/generated.go @@ -1022,6 +1022,7 @@ type ComplexityRoot struct { Alias func(childComplexity int) int BasicAuthPassword func(childComplexity int) int BasicAuthUsername func(childComplexity int) int + BgColor func(childComplexity int) int CreatedAt func(childComplexity int) int ID func(childComplexity int) int IsBasicAuthActive func(childComplexity int) int @@ -6467,6 +6468,13 @@ func (e *executableSchema) Complexity(typeName, field string, childComplexity in return e.complexity.Story.BasicAuthUsername(childComplexity), true + case "Story.bgColor": + if e.complexity.Story.BgColor == nil { + break + } + + return e.complexity.Story.BgColor(childComplexity), true + case "Story.createdAt": if e.complexity.Story.CreatedAt == nil { break @@ -8988,6 +8996,7 @@ extend type Mutation { sceneId: ID! scene: Scene panelPosition: Position! + bgColor: String isBasicAuthActive: Boolean! basicAuthUsername: String! @@ -9044,6 +9053,7 @@ input UpdateStoryInput { title: String index: Int panelPosition: Position + bgColor: String # publishment isBasicAuthActive: Boolean @@ -14493,6 +14503,8 @@ func (ec *executionContext) fieldContext_CreateStoryBlockPayload_story(ctx conte return ec.fieldContext_Story_scene(ctx, field) case "panelPosition": return ec.fieldContext_Story_panelPosition(ctx, field) + case "bgColor": + return ec.fieldContext_Story_bgColor(ctx, field) case "isBasicAuthActive": return ec.fieldContext_Story_isBasicAuthActive(ctx, field) case "basicAuthUsername": @@ -17294,6 +17306,8 @@ func (ec *executionContext) fieldContext_DeleteStoryPagePayload_story(ctx contex return ec.fieldContext_Story_scene(ctx, field) case "panelPosition": return ec.fieldContext_Story_panelPosition(ctx, field) + case "bgColor": + return ec.fieldContext_Story_bgColor(ctx, field) case "isBasicAuthActive": return ec.fieldContext_Story_isBasicAuthActive(ctx, field) case "basicAuthUsername": @@ -25730,6 +25744,8 @@ func (ec *executionContext) fieldContext_MoveStoryBlockPayload_story(ctx context return ec.fieldContext_Story_scene(ctx, field) case "panelPosition": return ec.fieldContext_Story_panelPosition(ctx, field) + case "bgColor": + return ec.fieldContext_Story_bgColor(ctx, field) case "isBasicAuthActive": return ec.fieldContext_Story_isBasicAuthActive(ctx, field) case "basicAuthUsername": @@ -25976,6 +25992,8 @@ func (ec *executionContext) fieldContext_MoveStoryPagePayload_story(ctx context. return ec.fieldContext_Story_scene(ctx, field) case "panelPosition": return ec.fieldContext_Story_panelPosition(ctx, field) + case "bgColor": + return ec.fieldContext_Story_bgColor(ctx, field) case "isBasicAuthActive": return ec.fieldContext_Story_isBasicAuthActive(ctx, field) case "basicAuthUsername": @@ -26194,6 +26212,8 @@ func (ec *executionContext) fieldContext_MoveStoryPayload_stories(ctx context.Co return ec.fieldContext_Story_scene(ctx, field) case "panelPosition": return ec.fieldContext_Story_panelPosition(ctx, field) + case "bgColor": + return ec.fieldContext_Story_bgColor(ctx, field) case "isBasicAuthActive": return ec.fieldContext_Story_isBasicAuthActive(ctx, field) case "basicAuthUsername": @@ -42050,6 +42070,8 @@ func (ec *executionContext) fieldContext_RemoveStoryBlockPayload_story(ctx conte return ec.fieldContext_Story_scene(ctx, field) case "panelPosition": return ec.fieldContext_Story_panelPosition(ctx, field) + case "bgColor": + return ec.fieldContext_Story_bgColor(ctx, field) case "isBasicAuthActive": return ec.fieldContext_Story_isBasicAuthActive(ctx, field) case "basicAuthUsername": @@ -43203,6 +43225,8 @@ func (ec *executionContext) fieldContext_Scene_stories(ctx context.Context, fiel return ec.fieldContext_Story_scene(ctx, field) case "panelPosition": return ec.fieldContext_Story_panelPosition(ctx, field) + case "bgColor": + return ec.fieldContext_Story_bgColor(ctx, field) case "isBasicAuthActive": return ec.fieldContext_Story_isBasicAuthActive(ctx, field) case "basicAuthUsername": @@ -45112,6 +45136,47 @@ func (ec *executionContext) fieldContext_Story_panelPosition(ctx context.Context return fc, nil } +func (ec *executionContext) _Story_bgColor(ctx context.Context, field graphql.CollectedField, obj *gqlmodel.Story) (ret graphql.Marshaler) { + fc, err := ec.fieldContext_Story_bgColor(ctx, field) + if err != nil { + return graphql.Null + } + ctx = graphql.WithFieldContext(ctx, fc) + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = graphql.Null + } + }() + resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return obj.BgColor, nil + }) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + if resTmp == nil { + return graphql.Null + } + res := resTmp.(*string) + fc.Result = res + return ec.marshalOString2áš–string(ctx, field.Selections, res) +} + +func (ec *executionContext) fieldContext_Story_bgColor(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { + fc = &graphql.FieldContext{ + Object: "Story", + Field: field, + IsMethod: false, + IsResolver: false, + Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { + return nil, errors.New("field of type String does not have child fields") + }, + } + return fc, nil +} + func (ec *executionContext) _Story_isBasicAuthActive(ctx context.Context, field graphql.CollectedField, obj *gqlmodel.Story) (ret graphql.Marshaler) { fc, err := ec.fieldContext_Story_isBasicAuthActive(ctx, field) if err != nil { @@ -46617,6 +46682,8 @@ func (ec *executionContext) fieldContext_StoryPagePayload_story(ctx context.Cont return ec.fieldContext_Story_scene(ctx, field) case "panelPosition": return ec.fieldContext_Story_panelPosition(ctx, field) + case "bgColor": + return ec.fieldContext_Story_bgColor(ctx, field) case "isBasicAuthActive": return ec.fieldContext_Story_isBasicAuthActive(ctx, field) case "basicAuthUsername": @@ -46703,6 +46770,8 @@ func (ec *executionContext) fieldContext_StoryPayload_story(ctx context.Context, return ec.fieldContext_Story_scene(ctx, field) case "panelPosition": return ec.fieldContext_Story_panelPosition(ctx, field) + case "bgColor": + return ec.fieldContext_Story_bgColor(ctx, field) case "isBasicAuthActive": return ec.fieldContext_Story_isBasicAuthActive(ctx, field) case "basicAuthUsername": @@ -57078,7 +57147,7 @@ func (ec *executionContext) unmarshalInputUpdateStoryInput(ctx context.Context, asMap[k] = v } - fieldsInOrder := [...]string{"sceneId", "storyId", "title", "index", "panelPosition", "isBasicAuthActive", "basicAuthUsername", "basicAuthPassword", "alias", "publicTitle", "publicDescription", "publicImage", "publicNoIndex", "deletePublicImage"} + fieldsInOrder := [...]string{"sceneId", "storyId", "title", "index", "panelPosition", "bgColor", "isBasicAuthActive", "basicAuthUsername", "basicAuthPassword", "alias", "publicTitle", "publicDescription", "publicImage", "publicNoIndex", "deletePublicImage"} for _, k := range fieldsInOrder { v, ok := asMap[k] if !ok { @@ -57125,6 +57194,14 @@ func (ec *executionContext) unmarshalInputUpdateStoryInput(ctx context.Context, if err != nil { return it, err } + case "bgColor": + var err error + + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("bgColor")) + it.BgColor, err = ec.unmarshalOString2áš–string(ctx, v) + if err != nil { + return it, err + } case "isBasicAuthActive": var err error @@ -65803,6 +65880,10 @@ func (ec *executionContext) _Story(ctx context.Context, sel ast.SelectionSet, ob if out.Values[i] == graphql.Null { atomic.AddUint32(&invalids, 1) } + case "bgColor": + + out.Values[i] = ec._Story_bgColor(ctx, field, obj) + case "isBasicAuthActive": out.Values[i] = ec._Story_isBasicAuthActive(ctx, field, obj) diff --git a/server/internal/adapter/gql/gqlmodel/convert_storytelling.go b/server/internal/adapter/gql/gqlmodel/convert_storytelling.go index eb429904e9..d2a1374b36 100644 --- a/server/internal/adapter/gql/gqlmodel/convert_storytelling.go +++ b/server/internal/adapter/gql/gqlmodel/convert_storytelling.go @@ -21,6 +21,7 @@ func ToStory(s *storytelling.Story) *Story { UpdatedAt: s.UpdatedAt(), PublishedAt: s.PublishedAt(), PanelPosition: ToStoryPosition(s.PanelPosition()), + BgColor: ToStoryBgColor(s.BgColor()), IsBasicAuthActive: s.IsBasicAuthActive(), BasicAuthUsername: s.BasicAuthUsername(), @@ -113,6 +114,10 @@ func ToStoryPosition(v storytelling.Position) Position { return "" } +func ToStoryBgColor(bg string) *string { + return &bg +} + func FromStoryPositionRef(v *Position) *storytelling.Position { if v == nil { return nil diff --git a/server/internal/adapter/gql/gqlmodel/models_gen.go b/server/internal/adapter/gql/gqlmodel/models_gen.go index eef7a1674e..0ffd7f5865 100644 --- a/server/internal/adapter/gql/gqlmodel/models_gen.go +++ b/server/internal/adapter/gql/gqlmodel/models_gen.go @@ -1273,6 +1273,7 @@ type Story struct { SceneID ID `json:"sceneId"` Scene *Scene `json:"scene"` PanelPosition Position `json:"panelPosition"` + BgColor *string `json:"bgColor"` IsBasicAuthActive bool `json:"isBasicAuthActive"` BasicAuthUsername string `json:"basicAuthUsername"` BasicAuthPassword string `json:"basicAuthPassword"` @@ -1538,6 +1539,7 @@ type UpdateStoryInput struct { Title *string `json:"title"` Index *int `json:"index"` PanelPosition *Position `json:"panelPosition"` + BgColor *string `json:"bgColor"` IsBasicAuthActive *bool `json:"isBasicAuthActive"` BasicAuthUsername *string `json:"basicAuthUsername"` BasicAuthPassword *string `json:"basicAuthPassword"` diff --git a/server/internal/adapter/gql/resolver_mutation_storytelling.go b/server/internal/adapter/gql/resolver_mutation_storytelling.go index 68e34c1a7a..36133680a4 100644 --- a/server/internal/adapter/gql/resolver_mutation_storytelling.go +++ b/server/internal/adapter/gql/resolver_mutation_storytelling.go @@ -44,6 +44,7 @@ func (r *mutationResolver) UpdateStory(ctx context.Context, input gqlmodel.Updat Title: input.Title, Index: input.Index, PanelPosition: gqlmodel.FromStoryPositionRef(input.PanelPosition), + BgColor: input.BgColor, IsBasicAuthActive: input.IsBasicAuthActive, BasicAuthUsername: input.BasicAuthUsername, diff --git a/server/internal/infrastructure/mongo/mongodoc/storytelling.go b/server/internal/infrastructure/mongo/mongodoc/storytelling.go index fe12fdac05..3308abb9e5 100644 --- a/server/internal/infrastructure/mongo/mongodoc/storytelling.go +++ b/server/internal/infrastructure/mongo/mongodoc/storytelling.go @@ -22,6 +22,7 @@ type StorytellingDocument struct { UpdatedAt time.Time Index int PanelPosition string + BgColor string IsBasicAuthActive bool BasicAuthUsername string @@ -72,6 +73,7 @@ func NewStorytelling(s *storytelling.Story) (*StorytellingDocument, string) { UpdatedAt: s.UpdatedAt(), Index: 1, PanelPosition: string(s.PanelPosition()), + BgColor: s.BgColor(), IsBasicAuthActive: s.IsBasicAuthActive(), BasicAuthUsername: s.BasicAuthUsername(), @@ -179,6 +181,7 @@ func (d *StorytellingDocument) Model() (*storytelling.Story, error) { Alias(d.Alias). Status(storytelling.PublishmentStatus(d.Status)). PanelPosition(storytelling.Position(d.PanelPosition)). + BgColor(d.BgColor). PublishedAt(d.PublishedAt). UpdatedAt(d.UpdatedAt). Pages(storytelling.NewPageList(pages)). diff --git a/server/internal/usecase/interactor/storytelling.go b/server/internal/usecase/interactor/storytelling.go index 9102f44213..fc4ce39d6b 100644 --- a/server/internal/usecase/interactor/storytelling.go +++ b/server/internal/usecase/interactor/storytelling.go @@ -170,6 +170,10 @@ func (i *Storytelling) Update(ctx context.Context, inp interfaces.UpdateStoryInp story.SetPanelPosition(*inp.PanelPosition) } + if inp.BgColor != nil { + story.SetBgColor(*inp.BgColor) + } + oldAlias := story.Alias() if inp.Alias != nil && *inp.Alias != oldAlias { if err := story.UpdateAlias(*inp.Alias); err != nil { diff --git a/server/internal/usecase/interfaces/story.go b/server/internal/usecase/interfaces/story.go index b7671a18af..a6529bb8e9 100644 --- a/server/internal/usecase/interfaces/story.go +++ b/server/internal/usecase/interfaces/story.go @@ -23,6 +23,7 @@ type UpdateStoryInput struct { Title *string Index *int PanelPosition *storytelling.Position + BgColor *string IsBasicAuthActive *bool BasicAuthUsername *string diff --git a/server/pkg/scene/builder/story.go b/server/pkg/scene/builder/story.go index 77fcf4f72f..78d2ceed20 100644 --- a/server/pkg/scene/builder/story.go +++ b/server/pkg/scene/builder/story.go @@ -9,14 +9,17 @@ import ( ) type storyJSON struct { - ID string `json:"id"` - Property propertyJSON `json:"property"` - Pages []pageJSON `json:"pages"` + ID string `json:"id"` + Property propertyJSON `json:"property"` + Pages []pageJSON `json:"pages"` + PanelPosition string `json:"position"` + BgColor string `json:"bgColor"` } type pageJSON struct { ID string `json:"id"` Property propertyJSON `json:"property"` + Title string `json:"title"` Blocks []blockJSON `json:"blocks"` Swipeable bool `json:"swipeable"` SwipeableLayers []string `json:"swipeableLayers"` @@ -45,6 +48,8 @@ func (b *Builder) storyJSON(ctx context.Context, p []*property.Property) (*story } return b.pageJSON(ctx, *page, p), true }), + PanelPosition: string(b.story.PanelPosition()), + BgColor: b.story.BgColor(), }, nil } @@ -52,6 +57,7 @@ func (b *Builder) pageJSON(ctx context.Context, page storytelling.Page, p []*pro return pageJSON{ ID: page.Id().String(), Property: b.property(ctx, findProperty(p, page.Property())), + Title: page.Title(), Blocks: lo.FilterMap(page.Blocks(), func(block *storytelling.Block, _ int) (blockJSON, bool) { if block == nil { return blockJSON{}, false diff --git a/server/pkg/storytelling/story.go b/server/pkg/storytelling/story.go index 896669f8fd..7f6ce1d3a5 100644 --- a/server/pkg/storytelling/story.go +++ b/server/pkg/storytelling/story.go @@ -24,6 +24,7 @@ type Story struct { title string pages *PageList panelPosition Position + bgColor string updatedAt time.Time alias string @@ -116,6 +117,10 @@ func (s *Story) SetPanelPosition(panelPosition Position) { s.panelPosition = panelPosition } +func (s *Story) SetBgColor(bgColor string) { + s.bgColor = bgColor +} + func (s *Story) Rename(name string) { s.title = name s.updatedAt = util.Now() @@ -160,6 +165,10 @@ func (s *Story) PanelPosition() Position { return s.panelPosition } +func (s *Story) BgColor() string { + return s.bgColor +} + func (s *Story) ValidateProperties(pm property.Map) error { if pm == nil { return nil diff --git a/server/pkg/storytelling/story_bulider.go b/server/pkg/storytelling/story_bulider.go index 9010849fe2..006a14a299 100644 --- a/server/pkg/storytelling/story_bulider.go +++ b/server/pkg/storytelling/story_bulider.go @@ -68,6 +68,11 @@ func (b *StoryBuilder) PanelPosition(position Position) *StoryBuilder { return b } +func (b *StoryBuilder) BgColor(bgColor string) *StoryBuilder { + b.s.bgColor = bgColor + return b +} + func (b *StoryBuilder) Alias(alias string) *StoryBuilder { b.s.alias = alias return b diff --git a/server/pkg/storytelling/story_test.go b/server/pkg/storytelling/story_test.go index 212566db19..47d812f07e 100644 --- a/server/pkg/storytelling/story_test.go +++ b/server/pkg/storytelling/story_test.go @@ -66,6 +66,9 @@ func TestStory_SettersGetters(t *testing.T) { s.SetPanelPosition(PositionLeft) assert.Equal(t, PositionLeft, s.PanelPosition()) + s.SetBgColor("test") + assert.Equal(t, "test", s.BgColor()) + err := s.SetBasicAuth(true, nil, nil) assert.Equal(t, ErrBasicAuthUserNamePasswordEmpty, err)