Skip to content
This repository has been archived by the owner on Aug 16, 2022. It is now read-only.

feat: update tag #49

Merged
merged 19 commits into from
Oct 23, 2021
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 13 additions & 3 deletions internal/adapter/gql/generated.go

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

13 changes: 13 additions & 0 deletions internal/adapter/gql/gqlmodel/convert_tag.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,16 @@ func ToTagGroup(tg *tag.Group) *TagGroup {
Tags: ids,
}
}

func ToTag(t tag.Tag) Tag {
if t == nil {
return nil
}
switch ty := t.(type) {
case *tag.Item:
return ToTagItem(ty)
case *tag.Group:
return ToTagGroup(ty)
}
return nil
}
2 changes: 1 addition & 1 deletion internal/adapter/gql/gqlmodel/models_gen.go

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

2 changes: 1 addition & 1 deletion internal/adapter/gql/resolver_mutation_tag.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ func (r *mutationResolver) UpdateTag(ctx context.Context, input gqlmodel.UpdateT
return nil, err
}
return &gqlmodel.UpdateTagPayload{
Tag: gqlmodel.ToTagGroup(tag),
Tag: gqlmodel.ToTag(*tag),
}, nil
}

Expand Down
11 changes: 6 additions & 5 deletions internal/usecase/interactor/tag.go
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ func (i *Tag) DetachItemFromGroup(ctx context.Context, inp interfaces.DetachItem
return tg, nil
}

func (i *Tag) UpdateTag(ctx context.Context, inp interfaces.UpdateTagParam, operator *usecase.Operator) (*tag.Group, error) {
func (i *Tag) UpdateTag(ctx context.Context, inp interfaces.UpdateTagParam, operator *usecase.Operator) (*tag.Tag, error) {
tx, err := i.transaction.Begin()
if err != nil {
return nil, err
Expand All @@ -193,19 +193,20 @@ func (i *Tag) UpdateTag(ctx context.Context, inp interfaces.UpdateTagParam, oper
return nil, interfaces.ErrOperationDenied
}

tg, err := i.tagRepo.FindGroupByID(ctx, inp.TagID, []id.SceneID{inp.SceneID})
tg, err := i.tagRepo.FindByID(ctx, inp.TagID, []id.SceneID{inp.SceneID})
t := *tg
if err != nil {
return nil, err
}
mimoham24 marked this conversation as resolved.
Show resolved Hide resolved

if inp.Label != nil {
tg.Rename(*inp.Label)
t.Rename(*inp.Label)
}

err = i.tagRepo.Save(ctx, tg)
err = i.tagRepo.Save(ctx, t)
if err != nil {
return nil, err
}
tx.Commit()
return tg, nil
return &t, nil
}
2 changes: 1 addition & 1 deletion internal/usecase/interfaces/tag.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,5 +41,5 @@ type Tag interface {
CreateGroup(context.Context, CreateTagGroupParam, *usecase.Operator) (*tag.Group, error)
AttachItemToGroup(context.Context, AttachItemToGroupParam, *usecase.Operator) (*tag.Group, error)
DetachItemFromGroup(context.Context, DetachItemToGroupParam, *usecase.Operator) (*tag.Group, error)
UpdateTag(context.Context, UpdateTagParam, *usecase.Operator) (*tag.Group, error)
UpdateTag(context.Context, UpdateTagParam, *usecase.Operator) (*tag.Tag, error)
}
4 changes: 0 additions & 4 deletions pkg/tag/group.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,3 @@ type Group struct {
func (g *Group) Tags() *List {
return g.tags
}

func (g *Group) Rename(s string) {
g.label = s
}
5 changes: 5 additions & 0 deletions pkg/tag/tag.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ type Tag interface {
ID() id.TagID
Scene() id.SceneID
Label() string
Rename(string)
}

func (t *tag) ID() id.TagID {
Expand All @@ -35,6 +36,10 @@ func (t *tag) Label() string {
return t.label
}

func (t *tag) Rename(s string) {
t.label = s
}

func ToTagGroup(t Tag) *Group {
if tg, ok := t.(*Group); ok {
return tg
Expand Down
8 changes: 8 additions & 0 deletions pkg/tag/tag_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,11 @@ func TestToTagItem(t *testing.T) {
item2 := ToTagItem(&tag2)
assert.NotNil(t, item2)
}

func TestTag_Rename(t *testing.T) {
tt := tag{
label: "xxx",
}
tt.Rename("changed")
assert.Equal(t, "changed", tt.Label())
}
2 changes: 1 addition & 1 deletion schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -1327,7 +1327,7 @@ type DetachTagItemFromGroupPayload {
}

type UpdateTagPayload {
tag: TagGroup!
tag: Tag!
}

type AttachTagToLayerPayload{
Expand Down