This repository has been archived by the owner on Aug 16, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: create tag group and tag item (#45)
* tag item and group schema * feat: creat tags (GQL schema) * tag items and tag groups resolvers * datalayer (dummy memory) and usecases * receive list by reference * check if nil for list * resolve notes * generate new models
- Loading branch information
Showing
17 changed files
with
1,622 additions
and
5 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package gqlmodel | ||
|
||
import ( | ||
"github.com/reearth/reearth-backend/pkg/id" | ||
"github.com/reearth/reearth-backend/pkg/tag" | ||
) | ||
|
||
func ToTagItem(ti *tag.Item) *TagItem { | ||
return &TagItem{ | ||
ID: ti.ID().ID(), | ||
SceneID: ti.Scene().ID(), | ||
Label: ti.Label(), | ||
LinkedDatasetID: ti.LinkedDatasetID().IDRef(), | ||
LinkedDatasetSchemaID: ti.LinkedDatasetSchemaID().IDRef(), | ||
LinkedDatasetFieldID: ti.LinkedDatasetFieldID().IDRef(), | ||
} | ||
} | ||
|
||
func ToTagGroup(tg *tag.Group) *TagGroup { | ||
tags := tg.Tags() | ||
tids := tags.Tags() | ||
var ids []*id.ID | ||
for _, tid := range tids { | ||
if !tid.IsNil() { | ||
ids = append(ids, tid.IDRef()) | ||
} | ||
} | ||
return &TagGroup{ | ||
ID: tg.ID().ID(), | ||
SceneID: tg.Scene().ID(), | ||
Label: tg.Label(), | ||
Tags: ids, | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package gql | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/reearth/reearth-backend/internal/adapter/gql/gqlmodel" | ||
"github.com/reearth/reearth-backend/internal/usecase/interfaces" | ||
"github.com/reearth/reearth-backend/pkg/id" | ||
) | ||
|
||
func (r *mutationResolver) CreateTagItem(ctx context.Context, input gqlmodel.CreateTagItemInput) (*gqlmodel.CreateTagItemPayload, error) { | ||
exit := trace(ctx) | ||
defer exit() | ||
|
||
tag, err := r.usecases.Tag.CreateItem(ctx, interfaces.CreateTagItemParam{ | ||
Label: input.Label, | ||
SceneID: id.SceneID(input.SceneID), | ||
LinkedDatasetSchemaID: id.DatasetSchemaIDFromRefID(input.LinkedDatasetSchemaID), | ||
LinkedDatasetID: id.DatasetIDFromRefID(input.LinkedDatasetID), | ||
LinkedDatasetField: id.DatasetSchemaFieldIDFromRefID(input.LinkedDatasetField), | ||
}, getOperator(ctx)) | ||
if err != nil { | ||
return nil, err | ||
} | ||
return &gqlmodel.CreateTagItemPayload{ | ||
Tag: gqlmodel.ToTagItem(tag), | ||
}, nil | ||
} | ||
|
||
func (r *mutationResolver) CreateTagGroup(ctx context.Context, input gqlmodel.CreateTagGroupInput) (*gqlmodel.CreateTagGroupPayload, error) { | ||
exit := trace(ctx) | ||
defer exit() | ||
|
||
tag, err := r.usecases.Tag.CreateGroup(ctx, interfaces.CreateTagGroupParam{ | ||
Label: input.Label, | ||
SceneID: id.SceneID(input.SceneID), | ||
Tags: id.TagIDsFromIDRef(input.Tags), | ||
}, getOperator(ctx)) | ||
if err != nil { | ||
return nil, err | ||
} | ||
return &gqlmodel.CreateTagGroupPayload{ | ||
Tag: gqlmodel.ToTagGroup(tag), | ||
}, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package gql | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/reearth/reearth-backend/internal/adapter/gql/gqlmodel" | ||
"github.com/reearth/reearth-backend/pkg/id" | ||
) | ||
|
||
type tagItemResolver struct{ *Resolver } | ||
|
||
func (r *Resolver) TagItem() TagItemResolver { | ||
return &tagItemResolver{r} | ||
} | ||
|
||
func (t tagItemResolver) LinkedDatasetSchema(ctx context.Context, obj *gqlmodel.TagItem) (*gqlmodel.DatasetSchema, error) { | ||
exit := trace(ctx) | ||
defer exit() | ||
|
||
if obj.LinkedDatasetID == nil { | ||
return nil, nil | ||
} | ||
return DataLoadersFromContext(ctx).DatasetSchema.Load(id.DatasetSchemaID(*obj.LinkedDatasetSchemaID)) | ||
} | ||
|
||
func (t tagItemResolver) LinkedDataset(ctx context.Context, obj *gqlmodel.TagItem) (*gqlmodel.Dataset, error) { | ||
exit := trace(ctx) | ||
defer exit() | ||
|
||
if obj.LinkedDatasetID == nil { | ||
return nil, nil | ||
} | ||
return DataLoadersFromContext(ctx).Dataset.Load(id.DatasetID(*obj.LinkedDatasetID)) | ||
} | ||
|
||
func (t tagItemResolver) LinkedDatasetField(ctx context.Context, obj *gqlmodel.TagItem) (*gqlmodel.DatasetField, error) { | ||
exit := trace(ctx) | ||
defer exit() | ||
|
||
if obj.LinkedDatasetID == nil { | ||
return nil, nil | ||
} | ||
ds, err := DataLoadersFromContext(ctx).Dataset.Load(id.DatasetID(*obj.LinkedDatasetID)) | ||
return ds.Field(*obj.LinkedDatasetFieldID), err | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
package memory | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/reearth/reearth-backend/internal/usecase/repo" | ||
"github.com/reearth/reearth-backend/pkg/id" | ||
"github.com/reearth/reearth-backend/pkg/tag" | ||
) | ||
|
||
type Tag struct { | ||
//lock sync.Mutex | ||
data map[id.TagID]tag.Tag | ||
} | ||
|
||
func NewTag() repo.Tag { | ||
return &Tag{ | ||
data: map[id.TagID]tag.Tag{}, | ||
} | ||
} | ||
|
||
func (t Tag) FindByID(ctx context.Context, tagID id.TagID, ids []id.SceneID) (*tag.Tag, error) { | ||
panic("implement me") | ||
} | ||
|
||
func (t Tag) FindByIDs(ctx context.Context, ids []id.TagID, ids2 []id.SceneID) ([]*tag.Tag, error) { | ||
panic("implement me") | ||
} | ||
|
||
func (t Tag) FindItemByID(ctx context.Context, tagID id.TagID, ids []id.SceneID) (*tag.Item, error) { | ||
panic("implement me") | ||
} | ||
|
||
func (t Tag) FindItemByIDs(ctx context.Context, ids []id.TagID, ids2 []id.SceneID) ([]*tag.Item, error) { | ||
panic("implement me") | ||
} | ||
|
||
func (t Tag) FindGroupByID(ctx context.Context, tagID id.TagID, ids []id.SceneID) (*tag.Group, error) { | ||
panic("implement me") | ||
} | ||
|
||
func (t Tag) FindGroupByIDs(ctx context.Context, ids []id.TagID, ids2 []id.SceneID) ([]*tag.Group, error) { | ||
panic("implement me") | ||
} | ||
|
||
func (t Tag) FindByScene(ctx context.Context, sceneID id.SceneID) ([]*tag.Tag, error) { | ||
panic("implement me") | ||
} | ||
|
||
func (t Tag) Save(ctx context.Context, t2 tag.Tag) error { | ||
panic("implement me") | ||
} | ||
|
||
func (t Tag) SaveAll(ctx context.Context, tags []*tag.Tag) error { | ||
panic("implement me") | ||
} | ||
|
||
func (t Tag) Remove(ctx context.Context, tagID id.TagID) error { | ||
panic("implement me") | ||
} | ||
|
||
func (t Tag) RemoveAll(ctx context.Context, ids []id.TagID) error { | ||
panic("implement me") | ||
} | ||
|
||
func (t Tag) RemoveByScene(ctx context.Context, sceneID id.SceneID) error { | ||
panic("implement me") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.