Skip to content

Commit

Permalink
chore(server): add bgColor w story in memory, refactors and add test
Browse files Browse the repository at this point in the history
  • Loading branch information
pyshx committed Nov 6, 2023
1 parent cea0d7b commit df9e959
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 2 deletions.
15 changes: 13 additions & 2 deletions server/e2e/gql_storytelling_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ func fetchSceneForStories(e *httpexpect.Expect, sID string) (GraphQLRequest, *ht
}
}
}
bgColor
}
__typename
}
Expand Down Expand Up @@ -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
Expand All @@ -195,6 +197,7 @@ func updateStory(e *httpexpect.Expect, storyID, sID string) (GraphQLRequest, *ht
"sceneId": sID,
"title": "test2",
"index": 0,
"bgColor": "newBG",
},
}

Expand Down Expand Up @@ -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)
}

Expand Down
5 changes: 5 additions & 0 deletions server/internal/adapter/gql/gqlmodel/convert_storytelling.go
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions server/internal/adapter/gql/resolver_mutation_storytelling.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"github.com/reearth/reearth/server/internal/adapter/gql/gqlmodel"
"github.com/reearth/reearth/server/internal/usecase/interfaces"
"github.com/reearth/reearth/server/pkg/id"
"github.com/reearth/reearthx/log"
"github.com/samber/lo"
)

Expand Down Expand Up @@ -38,6 +39,8 @@ func (r *mutationResolver) UpdateStory(ctx context.Context, input gqlmodel.Updat
return nil, err
}

log.Debugfc(ctx, "inp: %v", *input.BgColor)

inp := interfaces.UpdateStoryInput{
SceneID: sceneId,
StoryID: storyId,
Expand Down
3 changes: 3 additions & 0 deletions server/internal/infrastructure/mongo/mongodoc/storytelling.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ type StorytellingDocument struct {
UpdatedAt time.Time
Index int
PanelPosition string
BgColor string

IsBasicAuthActive bool
BasicAuthUsername string
Expand Down Expand Up @@ -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(),
Expand Down Expand Up @@ -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)).
Expand Down
5 changes: 5 additions & 0 deletions server/internal/usecase/interactor/storytelling.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
"github.com/reearth/reearth/server/pkg/scene/builder"
"github.com/reearth/reearth/server/pkg/storytelling"
"github.com/reearth/reearthx/account/accountusecase/accountrepo"
"github.com/reearth/reearthx/log"
"github.com/reearth/reearthx/rerror"
"github.com/reearth/reearthx/usecasex"
"github.com/samber/lo"
Expand Down Expand Up @@ -170,10 +171,14 @@ func (i *Storytelling) Update(ctx context.Context, inp interfaces.UpdateStoryInp
story.SetPanelPosition(*inp.PanelPosition)
}

log.Debugfc(ctx, "inp2: %v", *inp.BgColor)

if inp.BgColor != nil {
story.SetBgColor(*inp.BgColor)
}

log.Debugfc(ctx, "story.bgColor: %v", story.BgColor())

oldAlias := story.Alias()
if inp.Alias != nil && *inp.Alias != oldAlias {
if err := story.UpdateAlias(*inp.Alias); err != nil {
Expand Down
5 changes: 5 additions & 0 deletions server/pkg/storytelling/story_bulider.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions server/pkg/storytelling/story_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down

0 comments on commit df9e959

Please sign in to comment.