From 62d74d5bbb361bcb004942c67f505edcc6f37ce3 Mon Sep 17 00:00:00 2001 From: yk-eukarya <81808708+yk-eukarya@users.noreply.github.com> Date: Tue, 15 Oct 2024 10:17:57 +0200 Subject: [PATCH] feat(server): support CJK in fields keys (#1261) * imp * rollback FE changes --- server/e2e/integration_item_test.go | 35 +++--- server/e2e/publicapi_test.go | 21 ++-- .../gql/gqlmodel/convert_group_test.go | 4 +- .../adapter/gql/gqlmodel/convert_item_test.go | 5 +- .../gql/gqlmodel/convert_model_test.go | 7 +- .../gql/gqlmodel/convert_schema_test.go | 5 +- .../internal/adapter/integration/convert.go | 5 +- .../adapter/integration/item_import.go | 5 +- .../internal/adapter/integration/item_test.go | 5 +- .../internal/adapter/publicapi/types_test.go | 18 +-- .../infrastructure/memory/group_test.go | 7 +- .../infrastructure/memory/model_test.go | 7 +- .../infrastructure/mongo/group_test.go | 7 +- .../infrastructure/mongo/model_test.go | 11 +- .../infrastructure/mongo/mongodoc/group.go | 3 +- .../mongo/mongodoc/group_test.go | 6 +- .../infrastructure/mongo/mongodoc/model.go | 6 +- .../mongo/mongodoc/model_test.go | 6 +- .../infrastructure/mongo/mongodoc/schema.go | 3 +- server/internal/usecase/interactor/group.go | 7 +- server/internal/usecase/interactor/item.go | 3 +- .../internal/usecase/interactor/item_test.go | 23 ++-- server/internal/usecase/interactor/model.go | 9 +- .../internal/usecase/interactor/model_test.go | 11 +- server/internal/usecase/interactor/schema.go | 5 +- server/internal/usecase/interfaces/item.go | 3 +- server/pkg/exporters/csv_test.go | 65 +++++----- server/pkg/exporters/geojson_test.go | 49 ++++---- server/pkg/group/builder.go | 3 +- server/pkg/group/builder_test.go | 47 ++++--- server/pkg/group/group.go | 9 +- server/pkg/group/group_test.go | 55 ++++----- server/pkg/group/list_test.go | 13 +- server/pkg/id/key.go | 16 +-- server/pkg/id/key_test.go | 11 +- server/pkg/item/item_test.go | 15 ++- server/pkg/item/reference_test.go | 7 +- server/pkg/key/key.go | 11 -- server/pkg/model/builder.go | 7 +- server/pkg/model/builder_test.go | 115 +++++++++--------- server/pkg/model/list_test.go | 21 ++-- server/pkg/model/model.go | 14 +-- server/pkg/model/model_test.go | 59 +++++---- server/pkg/schema/corresponding_field.go | 3 +- server/pkg/schema/corresponding_field_test.go | 5 +- server/pkg/schema/field.go | 8 +- server/pkg/schema/field_builder.go | 6 +- server/pkg/schema/field_builder_test.go | 11 +- server/pkg/schema/field_test.go | 7 +- server/pkg/schema/list_test.go | 9 +- server/pkg/schema/package_test.go | 37 +++--- server/pkg/schema/schema.go | 3 +- server/pkg/schema/schema_test.go | 17 ++- 53 files changed, 403 insertions(+), 447 deletions(-) delete mode 100644 server/pkg/key/key.go diff --git a/server/e2e/integration_item_test.go b/server/e2e/integration_item_test.go index f3edcd4ac6..773baf6492 100644 --- a/server/e2e/integration_item_test.go +++ b/server/e2e/integration_item_test.go @@ -18,7 +18,6 @@ import ( "github.com/reearth/reearth-cms/server/pkg/id" "github.com/reearth/reearth-cms/server/pkg/integration" "github.com/reearth/reearth-cms/server/pkg/item" - "github.com/reearth/reearth-cms/server/pkg/key" "github.com/reearth/reearth-cms/server/pkg/model" "github.com/reearth/reearth-cms/server/pkg/operator" "github.com/reearth/reearth-cms/server/pkg/project" @@ -69,26 +68,26 @@ var ( thId4 = id.NewThreadID() thId5 = id.NewThreadID() icId = id.NewCommentID() - ikey1 = key.Random() - ikey2 = key.Random() - ikey3 = key.Random() - ikey4 = key.Random() ikey0 = id.RandomKey() + ikey1 = id.RandomKey() + ikey2 = id.RandomKey() + ikey3 = id.RandomKey() + ikey4 = id.RandomKey() pid = id.NewProjectID() sid0 = id.NewSchemaID() sid1 = id.NewSchemaID() sid2 = id.NewSchemaID() sid3 = id.NewSchemaID() palias = "PROJECT_ALIAS" - sfKey1 = key.Random() + sfKey1 = id.RandomKey() sfKey2 = id.NewKey("asset") - sfKey3 = key.Random() - sfKey4 = key.Random() + sfKey3 = id.RandomKey() + sfKey4 = id.RandomKey() sfKey5 = id.NewKey("asset-key") sfKey6 = id.NewKey("group-key") sfKey7 = id.NewKey("geometry-key") sfKey8 = id.NewKey("geometry-editor-key") - gKey1 = key.Random() + gKey1 = id.RandomKey() gId1 = id.NewItemGroupID() gId2 = id.NewItemGroupID() gId3 = id.NewItemGroupID() @@ -380,28 +379,28 @@ func baseSeeder(ctx context.Context, r *repo.Container) error { // endregion // Default value - msf1 := schema.NewField(schema.NewBool().TypeProperty()).NewID().Key(key.Random()).DefaultValue(schema.NewBool().TypeProperty().Type().Value(true).AsMultiple()).MustBuild() + msf1 := schema.NewField(schema.NewBool().TypeProperty()).NewID().Key(id.RandomKey()).DefaultValue(schema.NewBool().TypeProperty().Type().Value(true).AsMultiple()).MustBuild() sm := schema.New().NewID().Workspace(w.ID()).Project(pid).Fields([]*schema.Field{msf1}).MustBuild() if err := r.Schema.Save(ctx, sm); err != nil { return err } - gsf := schema.NewField(schema.NewText(nil).TypeProperty()).NewID().Key(key.Random()).DefaultValue(schema.NewText(nil).TypeProperty().Type().Value("default group").AsMultiple()).MustBuild() + gsf := schema.NewField(schema.NewText(nil).TypeProperty()).NewID().Key(id.RandomKey()).DefaultValue(schema.NewText(nil).TypeProperty().Type().Value("default group").AsMultiple()).MustBuild() gs := schema.New().NewID().Workspace(w.ID()).Project(pid).Fields([]*schema.Field{gsf}).MustBuild() if err := r.Schema.Save(ctx, gs); err != nil { return err } - gp := group.New().NewID().Name("group2").Project(pid).Key(key.Random()).Schema(gs.ID()).MustBuild() + gp := group.New().NewID().Name("group2").Project(pid).Key(id.RandomKey()).Schema(gs.ID()).MustBuild() if err := r.Group.Save(ctx, gp); err != nil { return err } - dvsf1 := schema.NewField(schema.NewText(nil).TypeProperty()).ID(dvsfId).Key(key.Random()).MustBuild() - dvsf2 := schema.NewField(schema.NewText(nil).TypeProperty()).NewID().Key(key.Random()).DefaultValue(schema.NewText(nil).TypeProperty().Type().Value("default").AsMultiple()).MustBuild() - dvsf3 := schema.NewField(schema.NewGroup(gp.ID()).TypeProperty()).NewID().Key(key.Random()).MustBuild() + dvsf1 := schema.NewField(schema.NewText(nil).TypeProperty()).ID(dvsfId).Key(id.RandomKey()).MustBuild() + dvsf2 := schema.NewField(schema.NewText(nil).TypeProperty()).NewID().Key(id.RandomKey()).DefaultValue(schema.NewText(nil).TypeProperty().Type().Value("default").AsMultiple()).MustBuild() + dvsf3 := schema.NewField(schema.NewGroup(gp.ID()).TypeProperty()).NewID().Key(id.RandomKey()).MustBuild() gst2 := schema.GeometryObjectSupportedTypeList{schema.GeometryObjectSupportedTypePoint, schema.GeometryObjectSupportedTypeLineString} gest2 := schema.GeometryEditorSupportedTypeList{schema.GeometryEditorSupportedTypePoint, schema.GeometryEditorSupportedTypeLineString} - dvsf4 := schema.NewField(schema.NewGeometryObject(gst2).TypeProperty()).NewID().Key(key.Random()).MustBuild() - dvsf5 := schema.NewField(schema.NewGeometryEditor(gest2).TypeProperty()).NewID().Key(key.Random()).MustBuild() + dvsf4 := schema.NewField(schema.NewGeometryObject(gst2).TypeProperty()).NewID().Key(id.RandomKey()).MustBuild() + dvsf5 := schema.NewField(schema.NewGeometryEditor(gest2).TypeProperty()).NewID().Key(id.RandomKey()).MustBuild() dvs1 := schema.New().NewID().Workspace(w.ID()).Project(pid).Fields([]*schema.Field{dvsf1, dvsf2, dvsf3, dvsf4, dvsf5}).MustBuild() if err := r.Schema.Save(ctx, dvs1); err != nil { @@ -412,7 +411,7 @@ func baseSeeder(ctx context.Context, r *repo.Container) error { Name("dvm"). Description("dvm desc"). Public(true). - Key(key.Random()). + Key(id.RandomKey()). Project(pid). Schema(dvs1.ID()). Metadata(sm.ID().Ref()). diff --git a/server/e2e/publicapi_test.go b/server/e2e/publicapi_test.go index f5991d8058..93705591f1 100644 --- a/server/e2e/publicapi_test.go +++ b/server/e2e/publicapi_test.go @@ -12,7 +12,6 @@ import ( "github.com/reearth/reearth-cms/server/pkg/asset" "github.com/reearth/reearth-cms/server/pkg/id" "github.com/reearth/reearth-cms/server/pkg/item" - "github.com/reearth/reearth-cms/server/pkg/key" "github.com/reearth/reearth-cms/server/pkg/model" "github.com/reearth/reearth-cms/server/pkg/project" "github.com/reearth/reearth-cms/server/pkg/schema" @@ -361,22 +360,22 @@ func publicAPISeeder(ctx context.Context, r *repo.Container) error { gst := schema.GeometryObjectSupportedTypeList{schema.GeometryObjectSupportedTypePoint, schema.GeometryObjectSupportedTypeLineString} gest := schema.GeometryEditorSupportedTypeList{schema.GeometryEditorSupportedTypePoint, schema.GeometryEditorSupportedTypeLineString} s := schema.New().NewID().Project(p1.ID()).Workspace(p1.Workspace()).Fields(schema.FieldList{ - schema.NewField(schema.NewText(nil).TypeProperty()).ID(fid).Name(publicAPIField1Key).Key(key.New(publicAPIField1Key)).MustBuild(), - schema.NewField(schema.NewAsset().TypeProperty()).NewID().Name(publicAPIField2Key).Key(key.New(publicAPIField2Key)).MustBuild(), - schema.NewField(schema.NewText(nil).TypeProperty()).NewID().Name(publicAPIField3Key).Key(key.New(publicAPIField3Key)).Multiple(true).MustBuild(), - schema.NewField(schema.NewAsset().TypeProperty()).NewID().Name(publicAPIField4Key).Key(key.New(publicAPIField4Key)).Multiple(true).MustBuild(), - schema.NewField(schema.NewGeometryObject(gst).TypeProperty()).NewID().Name(publicAPIField5Key).Key(key.New(publicAPIField5Key)).MustBuild(), - schema.NewField(schema.NewGeometryEditor(gest).TypeProperty()).NewID().Name(publicAPIField6Key).Key(key.New(publicAPIField6Key)).MustBuild(), + schema.NewField(schema.NewText(nil).TypeProperty()).ID(fid).Name(publicAPIField1Key).Key(id.NewKey(publicAPIField1Key)).MustBuild(), + schema.NewField(schema.NewAsset().TypeProperty()).NewID().Name(publicAPIField2Key).Key(id.NewKey(publicAPIField2Key)).MustBuild(), + schema.NewField(schema.NewText(nil).TypeProperty()).NewID().Name(publicAPIField3Key).Key(id.NewKey(publicAPIField3Key)).Multiple(true).MustBuild(), + schema.NewField(schema.NewAsset().TypeProperty()).NewID().Name(publicAPIField4Key).Key(id.NewKey(publicAPIField4Key)).Multiple(true).MustBuild(), + schema.NewField(schema.NewGeometryObject(gst).TypeProperty()).NewID().Name(publicAPIField5Key).Key(id.NewKey(publicAPIField5Key)).MustBuild(), + schema.NewField(schema.NewGeometryEditor(gest).TypeProperty()).NewID().Name(publicAPIField6Key).Key(id.NewKey(publicAPIField6Key)).MustBuild(), }).TitleField(fid.Ref()).MustBuild() s2 := schema.New().NewID().Project(p1.ID()).Workspace(p1.Workspace()).Fields(schema.FieldList{ - schema.NewField(schema.NewText(nil).TypeProperty()).ID(fid).Name(publicAPIField1Key).Key(key.New(publicAPIField1Key)).MustBuild(), + schema.NewField(schema.NewText(nil).TypeProperty()).ID(fid).Name(publicAPIField1Key).Key(id.NewKey(publicAPIField1Key)).MustBuild(), }).MustBuild() - m := model.New().ID(publicAPIModelID).Project(p1.ID()).Schema(s.ID()).Public(true).Key(key.New(publicAPIModelKey)).MustBuild() + m := model.New().ID(publicAPIModelID).Project(p1.ID()).Schema(s.ID()).Public(true).Key(id.NewKey(publicAPIModelKey)).MustBuild() // m2 is not a public model - m2 := model.New().ID(publicAPIModelID).Project(p1.ID()).Schema(s.ID()).Name(publicAPIModelKey2).Key(key.New(publicAPIModelKey2)).Public(false).MustBuild() - m3 := model.New().ID(publicAPIModelID).Project(p1.ID()).Schema(s2.ID()).Name(publicAPIModelKey3).Key(key.New(publicAPIModelKey3)).Public(true).MustBuild() + m2 := model.New().ID(publicAPIModelID).Project(p1.ID()).Schema(s.ID()).Name(publicAPIModelKey2).Key(id.NewKey(publicAPIModelKey2)).Public(false).MustBuild() + m3 := model.New().ID(publicAPIModelID).Project(p1.ID()).Schema(s2.ID()).Name(publicAPIModelKey3).Key(id.NewKey(publicAPIModelKey3)).Public(true).MustBuild() i1 := item.New().ID(publicAPIItem1ID).Model(m.ID()).Schema(s.ID()).Project(p1.ID()).Thread(id.NewThreadID()).User(uid).Fields([]*item.Field{ item.NewField(s.Fields()[0].ID(), value.TypeText.Value("aaa").AsMultiple(), nil), diff --git a/server/internal/adapter/gql/gqlmodel/convert_group_test.go b/server/internal/adapter/gql/gqlmodel/convert_group_test.go index 8313544c3b..e408e97076 100644 --- a/server/internal/adapter/gql/gqlmodel/convert_group_test.go +++ b/server/internal/adapter/gql/gqlmodel/convert_group_test.go @@ -4,7 +4,7 @@ import ( "testing" "github.com/reearth/reearth-cms/server/pkg/group" - "github.com/reearth/reearth-cms/server/pkg/key" + "github.com/reearth/reearth-cms/server/pkg/id" "github.com/reearth/reearth-cms/server/pkg/project" "github.com/reearth/reearth-cms/server/pkg/schema" "github.com/stretchr/testify/assert" @@ -14,7 +14,7 @@ func TestToGroup(t *testing.T) { mId := group.NewID() pId := project.NewID() sId := schema.NewID() - k := key.Random() + k := id.RandomKey() tests := []struct { name string group *group.Group diff --git a/server/internal/adapter/gql/gqlmodel/convert_item_test.go b/server/internal/adapter/gql/gqlmodel/convert_item_test.go index cd91bfc9d8..5628201cc5 100644 --- a/server/internal/adapter/gql/gqlmodel/convert_item_test.go +++ b/server/internal/adapter/gql/gqlmodel/convert_item_test.go @@ -7,7 +7,6 @@ import ( "github.com/reearth/reearth-cms/server/internal/usecase/interfaces" "github.com/reearth/reearth-cms/server/pkg/id" "github.com/reearth/reearth-cms/server/pkg/item" - "github.com/reearth/reearth-cms/server/pkg/key" "github.com/reearth/reearth-cms/server/pkg/schema" "github.com/reearth/reearth-cms/server/pkg/value" "github.com/reearth/reearth-cms/server/pkg/version" @@ -25,7 +24,7 @@ func TestToItem(t *testing.T) { nid := id.NewIntegrationID() tid := id.NewThreadID() pid := id.NewProjectID() - sf1 := schema.NewField(schema.NewText(lo.ToPtr(10)).TypeProperty()).NewID().Key(key.Random()).MustBuild() + sf1 := schema.NewField(schema.NewText(lo.ToPtr(10)).TypeProperty()).NewID().Key(id.RandomKey()).MustBuild() sf := []*schema.Field{sf1} s := schema.New().ID(sid).Fields(sf).Workspace(accountdomain.NewWorkspaceID()).TitleField(sf1.ID().Ref()).Project(pid).MustBuild() i := item.New(). @@ -128,7 +127,7 @@ func TestToVersionedItem(t *testing.T) { iid := id.NewItemID() sid := id.NewSchemaID() ref := "a" - sf1 := schema.NewField(schema.NewBool().TypeProperty()).NewID().Key(key.Random()).MustBuild() + sf1 := schema.NewField(schema.NewBool().TypeProperty()).NewID().Key(id.RandomKey()).MustBuild() sf := []*schema.Field{sf1} s := schema.New().ID(sid).Fields(sf).Workspace(accountdomain.NewWorkspaceID()).Project(pId).MustBuild() fs := []*item.Field{item.NewField(sf1.ID(), value.TypeBool.Value(true).AsMultiple(), nil)} diff --git a/server/internal/adapter/gql/gqlmodel/convert_model_test.go b/server/internal/adapter/gql/gqlmodel/convert_model_test.go index dde0e8b62b..38eaeb6457 100644 --- a/server/internal/adapter/gql/gqlmodel/convert_model_test.go +++ b/server/internal/adapter/gql/gqlmodel/convert_model_test.go @@ -1,10 +1,11 @@ package gqlmodel import ( - "github.com/samber/lo" "testing" - "github.com/reearth/reearth-cms/server/pkg/key" + "github.com/reearth/reearth-cms/server/pkg/id" + "github.com/samber/lo" + "github.com/reearth/reearth-cms/server/pkg/model" "github.com/reearth/reearth-cms/server/pkg/project" "github.com/reearth/reearth-cms/server/pkg/schema" @@ -15,7 +16,7 @@ func TestToModel(t *testing.T) { mId := model.NewID() pId := project.NewID() sId := schema.NewID() - k := key.Random() + k := id.RandomKey() tests := []struct { name string model *model.Model diff --git a/server/internal/adapter/gql/gqlmodel/convert_schema_test.go b/server/internal/adapter/gql/gqlmodel/convert_schema_test.go index d02e7331e6..b7b4978358 100644 --- a/server/internal/adapter/gql/gqlmodel/convert_schema_test.go +++ b/server/internal/adapter/gql/gqlmodel/convert_schema_test.go @@ -4,7 +4,6 @@ import ( "testing" "github.com/reearth/reearth-cms/server/pkg/id" - "github.com/reearth/reearth-cms/server/pkg/key" "github.com/reearth/reearth-cms/server/pkg/schema" "github.com/reearth/reearth-cms/server/pkg/value" "github.com/reearth/reearthx/account/accountdomain" @@ -17,7 +16,7 @@ func TestToSchema(t *testing.T) { pId := id.NewProjectID() sId := schema.NewID() fId := id.NewFieldID() - k := key.Random() + k := id.RandomKey() tests := []struct { name string schema *schema.Schema @@ -91,7 +90,7 @@ func TestToSchemaField(t *testing.T) { UpdatedAt(fid.Timestamp()). Name("N1"). Description("D1"). - Key(key.New("K123456")). + Key(id.NewKey("K123456")). Unique(true). Multiple(true). Required(true). diff --git a/server/internal/adapter/integration/convert.go b/server/internal/adapter/integration/convert.go index 0e32dfa567..3042944518 100644 --- a/server/internal/adapter/integration/convert.go +++ b/server/internal/adapter/integration/convert.go @@ -6,7 +6,6 @@ import ( "github.com/reearth/reearth-cms/server/pkg/integrationapi" "github.com/reearth/reearth-cms/server/pkg/item" "github.com/reearth/reearth-cms/server/pkg/item/view" - "github.com/reearth/reearth-cms/server/pkg/key" "github.com/reearth/reearth-cms/server/pkg/schema" "github.com/reearth/reearth-cms/server/pkg/value" "github.com/reearth/reearthx/usecasex" @@ -53,9 +52,9 @@ func fromItemFieldParam(f integrationapi.Field, sf *schema.Field) interfaces.Ite v = *f.Value } - var k *key.Key + var k *id.Key if f.Key != nil { - k = key.New(*f.Key).Ref() + k = id.NewKey(*f.Key).Ref() } return interfaces.ItemFieldParam{ diff --git a/server/internal/adapter/integration/item_import.go b/server/internal/adapter/integration/item_import.go index d760364618..029656cf91 100644 --- a/server/internal/adapter/integration/item_import.go +++ b/server/internal/adapter/integration/item_import.go @@ -13,7 +13,6 @@ import ( "github.com/reearth/reearth-cms/server/internal/usecase/interfaces" "github.com/reearth/reearth-cms/server/pkg/id" "github.com/reearth/reearth-cms/server/pkg/integrationapi" - key2 "github.com/reearth/reearth-cms/server/pkg/key" "github.com/reearth/reearth-cms/server/pkg/schema" "github.com/reearth/reearth-cms/server/pkg/value" "github.com/reearth/reearthx/i18n" @@ -179,7 +178,7 @@ func itemsFromJson(r io.Reader, isGeoJson bool, geoField *string, sp schema.Pack return nil, nil, rerror.ErrInvalidParams } - geoFieldKey := key2.New(*geoField) + geoFieldKey := id.NewKey(*geoField) if !geoFieldKey.IsValid() { return nil, nil, rerror.ErrInvalidParams } @@ -211,7 +210,7 @@ func itemsFromJson(r io.Reader, isGeoJson bool, geoField *string, sp schema.Pack if v == nil { continue } - key := key2.New(k) + key := id.NewKey(k) if !key.IsValid() { return nil, nil, rerror.ErrInvalidParams } diff --git a/server/internal/adapter/integration/item_test.go b/server/internal/adapter/integration/item_test.go index 1a60c338ec..f400707126 100644 --- a/server/internal/adapter/integration/item_test.go +++ b/server/internal/adapter/integration/item_test.go @@ -6,7 +6,6 @@ import ( "github.com/reearth/reearth-cms/server/internal/usecase/interfaces" "github.com/reearth/reearth-cms/server/pkg/id" "github.com/reearth/reearth-cms/server/pkg/integrationapi" - "github.com/reearth/reearth-cms/server/pkg/key" "github.com/reearth/reearth-cms/server/pkg/schema" "github.com/reearth/reearthx/account/accountdomain" "github.com/samber/lo" @@ -22,8 +21,8 @@ func Test_convertMetaFields(t *testing.T) { tag2 := schema.NewTag("日本語", schema.TagColorOrange) tf, _ := schema.NewFieldTag(schema.TagList{tag1, tag2}) - sf1 := schema.NewField(tf.TypeProperty()).NewID().Key(key.New("sf-1")).MustBuild() - sf2 := schema.NewField(schema.NewText(nil).TypeProperty()).NewID().Key(key.New("sf-1")).MustBuild() + sf1 := schema.NewField(tf.TypeProperty()).NewID().Key(id.NewKey("sf-1")).MustBuild() + sf2 := schema.NewField(schema.NewText(nil).TypeProperty()).NewID().Key(id.NewKey("sf-1")).MustBuild() var vi any = "日本語" var vi2 any = "xyz" s := schema.New().NewID().Fields(schema.FieldList{sf1, sf2}).Project(id.NewProjectID()).Workspace(accountdomain.NewWorkspaceID()).MustBuild() diff --git a/server/internal/adapter/publicapi/types_test.go b/server/internal/adapter/publicapi/types_test.go index f724591f4c..289681fe1a 100644 --- a/server/internal/adapter/publicapi/types_test.go +++ b/server/internal/adapter/publicapi/types_test.go @@ -2,13 +2,13 @@ package publicapi import ( "encoding/json" - "github.com/reearth/reearth-cms/server/pkg/group" "testing" + "github.com/reearth/reearth-cms/server/pkg/group" + "github.com/reearth/reearth-cms/server/pkg/asset" "github.com/reearth/reearth-cms/server/pkg/id" "github.com/reearth/reearth-cms/server/pkg/item" - "github.com/reearth/reearth-cms/server/pkg/key" "github.com/reearth/reearth-cms/server/pkg/schema" "github.com/reearth/reearth-cms/server/pkg/value" "github.com/reearth/reearthx/account/accountdomain" @@ -32,7 +32,7 @@ func TestNewItem(t *testing.T) { Project(id.NewProjectID()). Workspace(accountdomain.NewWorkspaceID()). Fields([]*schema.Field{ - schema.NewField(schema.NewText(nil).TypeProperty()).NewID().Key(key.New("test1")).MustBuild(), + schema.NewField(schema.NewText(nil).TypeProperty()).NewID().Key(id.NewKey("test1")).MustBuild(), }). MustBuild() @@ -40,7 +40,7 @@ func TestNewItem(t *testing.T) { NewID(). Name("test group"). Project(id.NewProjectID()). - Key(key.New("group1")). + Key(id.NewKey("group1")). Schema(s2.ID()). MustBuild() @@ -49,9 +49,9 @@ func TestNewItem(t *testing.T) { Project(id.NewProjectID()). Workspace(accountdomain.NewWorkspaceID()). Fields([]*schema.Field{ - schema.NewField(schema.NewText(nil).TypeProperty()).NewID().Key(key.New("aaaaa")).MustBuild(), - schema.NewField(schema.NewAsset().TypeProperty()).NewID().Key(key.New("bbbbb")).MustBuild(), - schema.NewField(schema.NewGroup(g.ID()).TypeProperty()).NewID().Key(key.New("ggggg")).MustBuild(), + schema.NewField(schema.NewText(nil).TypeProperty()).NewID().Key(id.NewKey("aaaaa")).MustBuild(), + schema.NewField(schema.NewAsset().TypeProperty()).NewID().Key(id.NewKey("bbbbb")).MustBuild(), + schema.NewField(schema.NewGroup(g.ID()).TypeProperty()).NewID().Key(id.NewKey("ggggg")).MustBuild(), }). MustBuild() ig := id.NewItemGroupID() @@ -112,8 +112,8 @@ func TestNewItem_Multiple(t *testing.T) { Project(id.NewProjectID()). Workspace(accountdomain.NewWorkspaceID()). Fields([]*schema.Field{ - schema.NewField(schema.NewText(nil).TypeProperty()).NewID().Key(key.New("aaaaa")).Multiple(true).MustBuild(), - schema.NewField(schema.NewAsset().TypeProperty()).NewID().Key(key.New("bbbbb")).Multiple(true).MustBuild(), + schema.NewField(schema.NewText(nil).TypeProperty()).NewID().Key(id.NewKey("aaaaa")).Multiple(true).MustBuild(), + schema.NewField(schema.NewAsset().TypeProperty()).NewID().Key(id.NewKey("bbbbb")).Multiple(true).MustBuild(), }). MustBuild() it := item.New(). diff --git a/server/internal/infrastructure/memory/group_test.go b/server/internal/infrastructure/memory/group_test.go index 090f506e0c..ad78dedf0e 100644 --- a/server/internal/infrastructure/memory/group_test.go +++ b/server/internal/infrastructure/memory/group_test.go @@ -7,7 +7,6 @@ import ( "github.com/reearth/reearth-cms/server/internal/usecase/repo" "github.com/reearth/reearth-cms/server/pkg/group" "github.com/reearth/reearth-cms/server/pkg/id" - "github.com/reearth/reearth-cms/server/pkg/key" "github.com/reearth/reearthx/rerror" "github.com/reearth/reearthx/util" "github.com/stretchr/testify/assert" @@ -34,7 +33,7 @@ func TestGroupRepo_FindByID(t *testing.T) { pid1 := id.NewProjectID() id1 := id.NewGroupID() sid1 := id.NewSchemaID() - k := key.New("T123456") + k := id.NewKey("T123456") m1 := group.New().ID(id1).Project(pid1).Schema(sid1).Key(k).MustBuild() tests := []struct { @@ -141,7 +140,7 @@ func TestGroupRepo_FindByIDs(t *testing.T) { id2 := id.NewGroupID() sid1 := id.NewSchemaID() sid2 := id.NewSchemaID() - k := key.New("T123456") + k := id.NewKey("T123456") m1 := group.New().ID(id1).Project(pid1).Schema(sid1).Key(k).MustBuild() m2 := group.New().ID(id2).Project(pid1).Schema(sid2).Key(k).MustBuild() @@ -258,7 +257,7 @@ func TestGroupRepo_FindByProject(t *testing.T) { id2 := id.NewGroupID() sid1 := id.NewSchemaID() sid2 := id.NewSchemaID() - k := key.New("T123456") + k := id.NewKey("T123456") m1 := group.New().ID(id1).Project(pid1).Schema(sid1).Key(k).MustBuild() m2 := group.New().ID(id2).Project(pid1).Schema(sid2).Key(k).MustBuild() diff --git a/server/internal/infrastructure/memory/model_test.go b/server/internal/infrastructure/memory/model_test.go index d235fa72ee..7ce6a43ab2 100644 --- a/server/internal/infrastructure/memory/model_test.go +++ b/server/internal/infrastructure/memory/model_test.go @@ -7,7 +7,6 @@ import ( "github.com/reearth/reearth-cms/server/internal/usecase/repo" "github.com/reearth/reearth-cms/server/pkg/id" - "github.com/reearth/reearth-cms/server/pkg/key" "github.com/reearth/reearth-cms/server/pkg/model" "github.com/reearth/reearthx/rerror" "github.com/reearth/reearthx/usecasex" @@ -37,7 +36,7 @@ func TestModelRepo_FindByID(t *testing.T) { pid1 := id.NewProjectID() id1 := id.NewModelID() sid1 := id.NewSchemaID() - k := key.New("T123456") + k := id.NewKey("T123456") m1 := model.New().ID(id1).Project(pid1).Schema(sid1).Key(k).UpdatedAt(mocknow).MustBuild() tests := []struct { @@ -142,7 +141,7 @@ func TestModelRepo_FindByIDs(t *testing.T) { id2 := id.NewModelID() sid1 := id.NewSchemaID() sid2 := id.NewSchemaID() - k := key.New("T123456") + k := id.NewKey("T123456") m1 := model.New().ID(id1).Project(pid1).Schema(sid1).Key(k).UpdatedAt(mocknow).MustBuild() m2 := model.New().ID(id2).Project(pid1).Schema(sid2).Key(k).UpdatedAt(mocknow).MustBuild() @@ -263,7 +262,7 @@ func TestModelRepo_FindByProject(t *testing.T) { id2 := id.NewModelID() sid1 := id.NewSchemaID() sid2 := id.NewSchemaID() - k := key.New("T123456") + k := id.NewKey("T123456") m1 := model.New().ID(id1).Project(pid1).Schema(sid1).Key(k).UpdatedAt(mocknow).MustBuild() m2 := model.New().ID(id2).Project(pid1).Schema(sid2).Key(k).UpdatedAt(mocknow).MustBuild() diff --git a/server/internal/infrastructure/mongo/group_test.go b/server/internal/infrastructure/mongo/group_test.go index 0f2590d6d8..ec2249b71f 100644 --- a/server/internal/infrastructure/mongo/group_test.go +++ b/server/internal/infrastructure/mongo/group_test.go @@ -7,7 +7,6 @@ import ( "github.com/reearth/reearth-cms/server/internal/usecase/repo" "github.com/reearth/reearth-cms/server/pkg/group" "github.com/reearth/reearth-cms/server/pkg/id" - "github.com/reearth/reearth-cms/server/pkg/key" "github.com/reearth/reearthx/mongox" "github.com/reearth/reearthx/mongox/mongotest" "github.com/reearth/reearthx/rerror" @@ -34,7 +33,7 @@ func TestGroupRepo_FindByID(t *testing.T) { pid1 := id.NewProjectID() id1 := id.NewGroupID() sid1 := id.NewSchemaID() - k := key.New("T123456") + k := id.NewKey("T123456") m1 := group.New().ID(id1).Project(pid1).Schema(sid1).Key(k).MustBuild() tests := []struct { @@ -144,7 +143,7 @@ func TestGroupRepo_FindByIDs(t *testing.T) { id2 := id.NewGroupID() sid1 := id.NewSchemaID() sid2 := id.NewSchemaID() - k := key.New("T123456") + k := id.NewKey("T123456") m1 := group.New().ID(id1).Project(pid1).Schema(sid1).Key(k).MustBuild() m2 := group.New().ID(id2).Project(pid1).Schema(sid2).Key(k).MustBuild() @@ -265,7 +264,7 @@ func TestGroupRepo_FindByProject(t *testing.T) { id2 := id.NewGroupID() sid1 := id.NewSchemaID() sid2 := id.NewSchemaID() - k := key.New("T123456") + k := id.NewKey("T123456") m1 := group.New().ID(id1).Project(pid1).Schema(sid1).Key(k).MustBuild() m2 := group.New().ID(id2).Project(pid1).Schema(sid2).Key(k).MustBuild() diff --git a/server/internal/infrastructure/mongo/model_test.go b/server/internal/infrastructure/mongo/model_test.go index 761a0abc95..0093870126 100644 --- a/server/internal/infrastructure/mongo/model_test.go +++ b/server/internal/infrastructure/mongo/model_test.go @@ -7,7 +7,6 @@ import ( "github.com/reearth/reearth-cms/server/internal/usecase/repo" "github.com/reearth/reearth-cms/server/pkg/id" - "github.com/reearth/reearth-cms/server/pkg/key" "github.com/reearth/reearth-cms/server/pkg/model" "github.com/reearth/reearthx/mongox" "github.com/reearth/reearthx/mongox/mongotest" @@ -37,7 +36,7 @@ func TestModelRepo_FindByID(t *testing.T) { pid1 := id.NewProjectID() id1 := id.NewModelID() sid1 := id.NewSchemaID() - k := key.New("T123456") + k := id.NewKey("T123456") m1 := model.New().ID(id1).Project(pid1).Schema(sid1).Key(k).UpdatedAt(mocknow).MustBuild() tests := []struct { @@ -146,7 +145,7 @@ func TestModelRepo_FindBySchema(t *testing.T) { pid1 := id.NewProjectID() id1 := id.NewModelID() sid1 := id.NewSchemaID() - k := key.New("T123456") + k := id.NewKey("T123456") m1 := model.New().ID(id1).Project(pid1).Schema(sid1).Key(k).UpdatedAt(mocknow).MustBuild() tests := []struct { @@ -257,7 +256,7 @@ func TestModelRepo_FindByIDs(t *testing.T) { id2 := id.NewModelID() sid1 := id.NewSchemaID() sid2 := id.NewSchemaID() - k := key.New("T123456") + k := id.NewKey("T123456") m1 := model.New().ID(id1).Project(pid1).Schema(sid1).Key(k).UpdatedAt(mocknow).MustBuild() m2 := model.New().ID(id2).Project(pid1).Schema(sid2).Key(k).UpdatedAt(mocknow).MustBuild() @@ -379,7 +378,7 @@ func TestModelRepo_FindByProject(t *testing.T) { id2 := id.NewModelID() sid1 := id.NewSchemaID() sid2 := id.NewSchemaID() - k := key.New("T123456") + k := id.NewKey("T123456") m1 := model.New().ID(id1).Project(pid1).Schema(sid1).Key(k).UpdatedAt(mocknow).MustBuild() m2 := model.New().ID(id2).Project(pid1).Schema(sid2).Key(k).UpdatedAt(mocknow).MustBuild() @@ -507,7 +506,7 @@ func TestModelRepo_FindByProjectAndKeyword(t *testing.T) { id2 := id.NewModelID() sid1 := id.NewSchemaID() sid2 := id.NewSchemaID() - k := key.New("T123456") + k := id.NewKey("T123456") m1 := model.New().ID(id1).Project(pid1).Schema(sid1).Key(k).Name("m1").UpdatedAt(mocknow).MustBuild() m2 := model.New().ID(id2).Project(pid1).Schema(sid2).Key(k).Name("m2").UpdatedAt(mocknow).MustBuild() diff --git a/server/internal/infrastructure/mongo/mongodoc/group.go b/server/internal/infrastructure/mongo/mongodoc/group.go index 846c7cc08b..8aa5fb0040 100644 --- a/server/internal/infrastructure/mongo/mongodoc/group.go +++ b/server/internal/infrastructure/mongo/mongodoc/group.go @@ -3,7 +3,6 @@ package mongodoc import ( "github.com/reearth/reearth-cms/server/pkg/group" "github.com/reearth/reearth-cms/server/pkg/id" - "github.com/reearth/reearth-cms/server/pkg/key" "github.com/reearth/reearthx/mongox" ) @@ -62,7 +61,7 @@ func (d *GroupDocument) Model() (*group.Group, error) { ID(mId). Name(d.Name). Description(d.Description). - Key(key.New(d.Key)). + Key(id.NewKey(d.Key)). Project(pId). Schema(sId). Order(d.Order). diff --git a/server/internal/infrastructure/mongo/mongodoc/group_test.go b/server/internal/infrastructure/mongo/mongodoc/group_test.go index 71c5e85705..1e2b802a4d 100644 --- a/server/internal/infrastructure/mongo/mongodoc/group_test.go +++ b/server/internal/infrastructure/mongo/mongodoc/group_test.go @@ -4,7 +4,7 @@ import ( "testing" "github.com/reearth/reearth-cms/server/pkg/group" - "github.com/reearth/reearth-cms/server/pkg/key" + "github.com/reearth/reearth-cms/server/pkg/id" "github.com/reearth/reearth-cms/server/pkg/project" "github.com/reearth/reearth-cms/server/pkg/schema" "github.com/stretchr/testify/assert" @@ -32,7 +32,7 @@ func TestGroupDocument_Group(t *testing.T) { want: group.New().ID(mId). Name("abc"). Description("xyz"). - Key(key.New("mmm123")). + Key(id.NewKey("mmm123")). Project(pId). Schema(sId). Order(1). @@ -110,7 +110,7 @@ func TestNewGroup(t *testing.T) { args: group.New().ID(mId). Name("abc"). Description("xyz"). - Key(key.New("mmm123")). + Key(id.NewKey("mmm123")). Project(pId). Schema(sId). Order(1). diff --git a/server/internal/infrastructure/mongo/mongodoc/model.go b/server/internal/infrastructure/mongo/mongodoc/model.go index 0f2d9604cc..baefb5eff5 100644 --- a/server/internal/infrastructure/mongo/mongodoc/model.go +++ b/server/internal/infrastructure/mongo/mongodoc/model.go @@ -1,11 +1,11 @@ package mongodoc import ( - "github.com/reearth/reearth-cms/server/pkg/model" "time" + "github.com/reearth/reearth-cms/server/pkg/model" + "github.com/reearth/reearth-cms/server/pkg/id" - "github.com/reearth/reearth-cms/server/pkg/key" "github.com/reearth/reearthx/mongox" ) @@ -71,7 +71,7 @@ func (d *ModelDocument) Model() (*model.Model, error) { Name(d.Name). Description(d.Description). UpdatedAt(d.UpdatedAt). - Key(key.New(d.Key)). + Key(id.NewKey(d.Key)). Public(d.Public). Project(pId). Metadata(id.SchemaIDFromRef(d.Metadata)). diff --git a/server/internal/infrastructure/mongo/mongodoc/model_test.go b/server/internal/infrastructure/mongo/mongodoc/model_test.go index cb125fa867..28f91a2c22 100644 --- a/server/internal/infrastructure/mongo/mongodoc/model_test.go +++ b/server/internal/infrastructure/mongo/mongodoc/model_test.go @@ -4,7 +4,7 @@ import ( "testing" "time" - "github.com/reearth/reearth-cms/server/pkg/key" + "github.com/reearth/reearth-cms/server/pkg/id" "github.com/reearth/reearth-cms/server/pkg/model" "github.com/reearth/reearth-cms/server/pkg/project" "github.com/reearth/reearth-cms/server/pkg/schema" @@ -36,7 +36,7 @@ func TestModelDocument_Model(t *testing.T) { want: model.New().ID(mId). Name("abc"). Description("xyz"). - Key(key.New("mmm123")). + Key(id.NewKey("mmm123")). Public(true). Project(pId). Metadata(smId.Ref()). @@ -120,7 +120,7 @@ func TestNewModel(t *testing.T) { args: model.New().ID(mId). Name("abc"). Description("xyz"). - Key(key.New("mmm123")). + Key(id.NewKey("mmm123")). Public(true). Project(pId). Schema(sId). diff --git a/server/internal/infrastructure/mongo/mongodoc/schema.go b/server/internal/infrastructure/mongo/mongodoc/schema.go index bf1cca9ec8..e3c040b54e 100644 --- a/server/internal/infrastructure/mongo/mongodoc/schema.go +++ b/server/internal/infrastructure/mongo/mongodoc/schema.go @@ -4,7 +4,6 @@ import ( "time" "github.com/reearth/reearth-cms/server/pkg/id" - "github.com/reearth/reearth-cms/server/pkg/key" "github.com/reearth/reearth-cms/server/pkg/schema" "github.com/reearth/reearth-cms/server/pkg/value" "github.com/reearth/reearthx/account/accountdomain" @@ -329,7 +328,7 @@ func (d *SchemaDocument) Model() (*schema.Schema, error) { Order(fd.Order). Required(fd.Required). Description(fd.Description). - Key(key.New(fd.Key)). + Key(id.NewKey(fd.Key)). UpdatedAt(fd.UpdatedAt). DefaultValue(fd.DefaultValue.MultipleValue()). Build() diff --git a/server/internal/usecase/interactor/group.go b/server/internal/usecase/interactor/group.go index 2058603c97..cf05543763 100644 --- a/server/internal/usecase/interactor/group.go +++ b/server/internal/usecase/interactor/group.go @@ -10,7 +10,6 @@ import ( "github.com/reearth/reearth-cms/server/internal/usecase/repo" "github.com/reearth/reearth-cms/server/pkg/group" "github.com/reearth/reearth-cms/server/pkg/id" - "github.com/reearth/reearth-cms/server/pkg/key" "github.com/reearth/reearth-cms/server/pkg/model" "github.com/reearth/reearth-cms/server/pkg/schema" "github.com/reearth/reearth-cms/server/pkg/value" @@ -81,7 +80,7 @@ func (i Group) Create(ctx context.Context, param interfaces.CreateGroupParam, op New(). NewID(). Schema(s.ID()). - Key(key.New(param.Key)). + Key(id.NewKey(param.Key)). Project(param.ProjectId). Name(param.Name) @@ -136,7 +135,7 @@ func (i Group) Update(ctx context.Context, param interfaces.UpdateGroupParam, op if gg != nil { return nil, id.ErrDuplicatedKey } - if err := g.SetKey(key.New(*param.Key)); err != nil { + if err := g.SetKey(id.NewKey(*param.Key)); err != nil { return nil, err } } @@ -151,7 +150,7 @@ func (i Group) Update(ctx context.Context, param interfaces.UpdateGroupParam, op func (i Group) CheckKey(ctx context.Context, pId id.ProjectID, s string) (bool, error) { return Run1(ctx, nil, i.repos, Usecase().Transaction(), func(ctx context.Context) (bool, error) { - if k := key.New(s); !k.IsValid() { + if k := id.NewKey(s); !k.IsValid() { return false, id.ErrInvalidKey } diff --git a/server/internal/usecase/interactor/item.go b/server/internal/usecase/interactor/item.go index 3ce744317d..6268f24193 100644 --- a/server/internal/usecase/interactor/item.go +++ b/server/internal/usecase/interactor/item.go @@ -13,7 +13,6 @@ import ( "github.com/reearth/reearth-cms/server/pkg/event" "github.com/reearth/reearth-cms/server/pkg/id" "github.com/reearth/reearth-cms/server/pkg/item" - "github.com/reearth/reearth-cms/server/pkg/key" "github.com/reearth/reearth-cms/server/pkg/request" "github.com/reearth/reearth-cms/server/pkg/schema" "github.com/reearth/reearth-cms/server/pkg/thread" @@ -391,7 +390,7 @@ func (i Item) Import(ctx context.Context, param interfaces.ImportItemsParam, ope Required(fieldParam.Required). Name(fieldParam.Name). Description(lo.FromPtr(fieldParam.Description)). - Key(key.New(fieldParam.Key)). + Key(id.NewKey(fieldParam.Key)). DefaultValue(fieldParam.DefaultValue). Build() if err != nil { diff --git a/server/internal/usecase/interactor/item_test.go b/server/internal/usecase/interactor/item_test.go index 0b336b94d8..6e5af5794c 100644 --- a/server/internal/usecase/interactor/item_test.go +++ b/server/internal/usecase/interactor/item_test.go @@ -12,7 +12,6 @@ import ( "github.com/reearth/reearth-cms/server/internal/usecase/repo" "github.com/reearth/reearth-cms/server/pkg/id" "github.com/reearth/reearth-cms/server/pkg/item" - "github.com/reearth/reearth-cms/server/pkg/key" "github.com/reearth/reearth-cms/server/pkg/model" "github.com/reearth/reearth-cms/server/pkg/project" "github.com/reearth/reearth-cms/server/pkg/request" @@ -175,7 +174,7 @@ func TestItem_FindBySchema(t *testing.T) { uid := accountdomain.NewUserID() wid := accountdomain.NewWorkspaceID() pid := id.NewProjectID() - sf1 := schema.NewField(schema.NewBool().TypeProperty()).NewID().Key(key.Random()).MustBuild() + sf1 := schema.NewField(schema.NewBool().TypeProperty()).NewID().Key(id.RandomKey()).MustBuild() s1 := schema.New().NewID().Workspace(wid).Project(pid).Fields(schema.FieldList{sf1}).MustBuild() s2 := schema.New().NewID().Workspace(wid).Project(pid).MustBuild() restore := util.MockNow(time.Now().Truncate(time.Millisecond).UTC()) @@ -479,9 +478,9 @@ func TestItem_IsItemReferenced(t *testing.T) { Description: "description", Required: true, } - sf1 := schema.NewField(schema.NewReference(id.NewModelID(), sid2, fid2.Ref(), cf1).TypeProperty()).ID(fid1).Name("f").Unique(true).Key(key.Random()).MustBuild() + sf1 := schema.NewField(schema.NewReference(id.NewModelID(), sid2, fid2.Ref(), cf1).TypeProperty()).ID(fid1).Name("f").Unique(true).Key(id.RandomKey()).MustBuild() s1 := schema.New().ID(sid1).Workspace(w).Project(prj.ID()).Fields(schema.FieldList{sf1}).MustBuild() - m1 := model.New().NewID().Schema(s1.ID()).Key(key.Random()).Project(s1.Project()).MustBuild() + m1 := model.New().NewID().Schema(s1.ID()).Key(id.RandomKey()).Project(s1.Project()).MustBuild() fs1 := []*item.Field{item.NewField(sf1.ID(), value.TypeReference.Value(id.NewItemID()).AsMultiple(), nil)} i1 := item.New().NewID().Schema(s1.ID()).Model(m1.ID()).Project(s1.Project()).Thread(id.NewThreadID()).Fields(fs1).MustBuild() @@ -491,16 +490,16 @@ func TestItem_IsItemReferenced(t *testing.T) { Description: "description", Required: true, } - sf2 := schema.NewField(schema.NewReference(id.NewModelID(), sid1, fid1.Ref(), cf2).TypeProperty()).ID(fid2).Name("f").Unique(true).Key(key.Random()).MustBuild() + sf2 := schema.NewField(schema.NewReference(id.NewModelID(), sid1, fid1.Ref(), cf2).TypeProperty()).ID(fid2).Name("f").Unique(true).Key(id.RandomKey()).MustBuild() s2 := schema.New().ID(sid2).Workspace(accountdomain.NewWorkspaceID()).Project(prj.ID()).Fields(schema.FieldList{sf2}).MustBuild() - m2 := model.New().NewID().Schema(s2.ID()).Key(key.Random()).Project(s2.Project()).MustBuild() + m2 := model.New().NewID().Schema(s2.ID()).Key(id.RandomKey()).Project(s2.Project()).MustBuild() fs2 := []*item.Field{item.NewField(sf2.ID(), value.TypeReference.Value(id.NewItemID()).AsMultiple(), nil)} i2 := item.New().NewID().Schema(s2.ID()).Model(m2.ID()).Project(s2.Project()).Thread(id.NewThreadID()).Fields(fs2).MustBuild() fid3 := id.NewFieldID() - sf3 := schema.NewField(schema.NewReference(id.NewModelID(), id.NewSchemaID(), nil, nil).TypeProperty()).ID(fid3).Name("f").Unique(true).Key(key.Random()).MustBuild() + sf3 := schema.NewField(schema.NewReference(id.NewModelID(), id.NewSchemaID(), nil, nil).TypeProperty()).ID(fid3).Name("f").Unique(true).Key(id.RandomKey()).MustBuild() s3 := schema.New().ID(sid2).Workspace(accountdomain.NewWorkspaceID()).Project(prj.ID()).Fields(schema.FieldList{sf3}).MustBuild() - m3 := model.New().NewID().Schema(s3.ID()).Key(key.Random()).Project(s3.Project()).MustBuild() + m3 := model.New().NewID().Schema(s3.ID()).Key(id.RandomKey()).Project(s3.Project()).MustBuild() fs3 := []*item.Field{item.NewField(sf3.ID(), value.TypeReference.Value(nil).AsMultiple(), nil)} i3 := item.New().NewID().Schema(s3.ID()).Model(m3.ID()).Project(s3.Project()).Thread(id.NewThreadID()).Fields(fs3).MustBuild() @@ -558,9 +557,9 @@ func TestItem_IsItemReferenced(t *testing.T) { func TestItem_Create(t *testing.T) { r := []workspace.Role{workspace.RoleReader, workspace.RoleWriter} prj := project.New().NewID().RequestRoles(r).MustBuild() - sf := schema.NewField(schema.NewText(lo.ToPtr(10)).TypeProperty()).NewID().Name("f").Unique(true).Key(key.Random()).MustBuild() + sf := schema.NewField(schema.NewText(lo.ToPtr(10)).TypeProperty()).NewID().Name("f").Unique(true).Key(id.RandomKey()).MustBuild() s := schema.New().NewID().Workspace(accountdomain.NewWorkspaceID()).Project(prj.ID()).Fields(schema.FieldList{sf}).MustBuild() - m := model.New().NewID().Schema(s.ID()).Key(key.Random()).Project(s.Project()).MustBuild() + m := model.New().NewID().Schema(s.ID()).Key(id.RandomKey()).Project(s.Project()).MustBuild() ctx := context.Background() db := memory.New() @@ -720,9 +719,9 @@ func TestItem_Create(t *testing.T) { func TestItem_Update(t *testing.T) { uId := accountdomain.NewUserID().Ref() prj := project.New().NewID().MustBuild() - sf := schema.NewField(schema.NewText(lo.ToPtr(10)).TypeProperty()).NewID().Name("f").Unique(true).Key(key.Random()).MustBuild() + sf := schema.NewField(schema.NewText(lo.ToPtr(10)).TypeProperty()).NewID().Name("f").Unique(true).Key(id.RandomKey()).MustBuild() s := schema.New().NewID().Workspace(accountdomain.NewWorkspaceID()).Project(prj.ID()).Fields(schema.FieldList{sf}).MustBuild() - m := model.New().NewID().Schema(s.ID()).Key(key.Random()).Project(s.Project()).MustBuild() + m := model.New().NewID().Schema(s.ID()).Key(id.RandomKey()).Project(s.Project()).MustBuild() i := item.New().NewID().User(*uId).Model(m.ID()).Project(s.Project()).Schema(s.ID()).Thread(id.NewThreadID()).MustBuild() i2 := item.New().NewID().User(*uId).Model(m.ID()).Project(s.Project()).Schema(s.ID()).Thread(id.NewThreadID()).MustBuild() i3 := item.New().NewID().User(accountdomain.NewUserID()).Model(m.ID()).Project(s.Project()).Schema(s.ID()).Thread(id.NewThreadID()).MustBuild() diff --git a/server/internal/usecase/interactor/model.go b/server/internal/usecase/interactor/model.go index 573390fbb6..11ff9adbd5 100644 --- a/server/internal/usecase/interactor/model.go +++ b/server/internal/usecase/interactor/model.go @@ -9,7 +9,6 @@ import ( "github.com/reearth/reearth-cms/server/internal/usecase/interfaces" "github.com/reearth/reearth-cms/server/internal/usecase/repo" "github.com/reearth/reearth-cms/server/pkg/id" - "github.com/reearth/reearth-cms/server/pkg/key" "github.com/reearth/reearth-cms/server/pkg/model" "github.com/reearth/reearth-cms/server/pkg/schema" "github.com/reearth/reearthx/i18n" @@ -109,9 +108,9 @@ func (i Model) Create(ctx context.Context, param interfaces.CreateModelParam, op mb = mb.Public(*param.Public) } if param.Key != nil { - mb = mb.Key(key.New(*param.Key)) + mb = mb.Key(id.NewKey(*param.Key)) } else { - mb = mb.Key(key.Random()) + mb = mb.Key(id.RandomKey()) } models, _, err := i.repos.Model.FindByProject(ctx, param.ProjectId, usecasex.CursorPagination{First: lo.ToPtr(int64(1000))}.Wrap()) if err != nil { @@ -154,7 +153,7 @@ func (i Model) Update(ctx context.Context, param interfaces.UpdateModelParam, op m.SetDescription(*param.Description) } if param.Key != nil { - if err := m.SetKey(key.New(*param.Key)); err != nil { + if err := m.SetKey(id.NewKey(*param.Key)); err != nil { return nil, err } } @@ -172,7 +171,7 @@ func (i Model) Update(ctx context.Context, param interfaces.UpdateModelParam, op func (i Model) CheckKey(ctx context.Context, pId id.ProjectID, s string) (bool, error) { return Run1(ctx, nil, i.repos, Usecase().Transaction(), func(ctx context.Context) (bool, error) { - if k := key.New(s); !k.IsValid() { + if k := id.NewKey(s); !k.IsValid() { return false, model.ErrInvalidKey } diff --git a/server/internal/usecase/interactor/model_test.go b/server/internal/usecase/interactor/model_test.go index 697f263fb3..9c412572f8 100644 --- a/server/internal/usecase/interactor/model_test.go +++ b/server/internal/usecase/interactor/model_test.go @@ -10,7 +10,6 @@ import ( "github.com/reearth/reearth-cms/server/internal/usecase/interfaces" "github.com/reearth/reearth-cms/server/internal/usecase/repo" "github.com/reearth/reearth-cms/server/pkg/id" - "github.com/reearth/reearth-cms/server/pkg/key" "github.com/reearth/reearth-cms/server/pkg/model" "github.com/reearth/reearth-cms/server/pkg/project" "github.com/reearth/reearthx/account/accountdomain/user" @@ -23,9 +22,9 @@ import ( func TestModel_FindByID(t *testing.T) { sid := id.NewSchemaID() id1 := id.NewModelID() - m1 := model.New().ID(id1).Key(key.Random()).Schema(sid).Project(id.NewProjectID()).MustBuild() + m1 := model.New().ID(id1).Key(id.RandomKey()).Schema(sid).Project(id.NewProjectID()).MustBuild() id2 := id.NewModelID() - m2 := model.New().ID(id2).Key(key.Random()).Schema(sid).Project(id.NewProjectID()).MustBuild() + m2 := model.New().ID(id2).Key(id.RandomKey()).Schema(sid).Project(id.NewProjectID()).MustBuild() op := &usecase.Operator{ AcOperator: &accountusecase.Operator{ @@ -133,7 +132,7 @@ func TestModel_CheckKey(t *testing.T) { name: "with different key", seeds: seeds{ model: []*model.Model{ - model.New().NewID().Key(key.Random()).Project(pId).Schema(id.NewSchemaID()).MustBuild(), + model.New().NewID().Key(id.RandomKey()).Project(pId).Schema(id.NewSchemaID()).MustBuild(), }, }, args: args{ @@ -148,7 +147,7 @@ func TestModel_CheckKey(t *testing.T) { name: "with same key", seeds: seeds{ model: []*model.Model{ - model.New().NewID().Key(key.New("test123")).Project(pId).Schema(id.NewSchemaID()).MustBuild(), + model.New().NewID().Key(id.NewKey("test123")).Project(pId).Schema(id.NewSchemaID()).MustBuild(), }, }, args: args{ @@ -163,7 +162,7 @@ func TestModel_CheckKey(t *testing.T) { name: "with same key different project", seeds: seeds{ model: []*model.Model{ - model.New().NewID().Key(key.New("test123")).Project(pId).Schema(id.NewSchemaID()).MustBuild(), + model.New().NewID().Key(id.NewKey("test123")).Project(pId).Schema(id.NewSchemaID()).MustBuild(), }, }, args: args{ diff --git a/server/internal/usecase/interactor/schema.go b/server/internal/usecase/interactor/schema.go index 73f3497707..b472a791f0 100644 --- a/server/internal/usecase/interactor/schema.go +++ b/server/internal/usecase/interactor/schema.go @@ -9,7 +9,6 @@ import ( "github.com/reearth/reearth-cms/server/internal/usecase/repo" "github.com/reearth/reearth-cms/server/pkg/group" "github.com/reearth/reearth-cms/server/pkg/id" - "github.com/reearth/reearth-cms/server/pkg/key" "github.com/reearth/reearth-cms/server/pkg/schema" "github.com/reearth/reearth-cms/server/pkg/value" "github.com/samber/lo" @@ -95,7 +94,7 @@ func (i Schema) CreateField(ctx context.Context, param interfaces.CreateFieldPar Required(param.Required). Name(param.Name). Description(lo.FromPtr(param.Description)). - Key(key.New(param.Key)). + Key(id.NewKey(param.Key)). DefaultValue(param.DefaultValue). Build() if err != nil { @@ -392,7 +391,7 @@ func updateField(param interfaces.UpdateFieldParam, f *schema.Field) error { } if param.Key != nil { - if err := f.SetKey(key.New(*param.Key)); err != nil { + if err := f.SetKey(id.NewKey(*param.Key)); err != nil { return err } } diff --git a/server/internal/usecase/interfaces/item.go b/server/internal/usecase/interfaces/item.go index 892025ce51..425706c1d9 100644 --- a/server/internal/usecase/interfaces/item.go +++ b/server/internal/usecase/interfaces/item.go @@ -7,7 +7,6 @@ import ( "github.com/reearth/reearth-cms/server/internal/usecase" "github.com/reearth/reearth-cms/server/pkg/id" "github.com/reearth/reearth-cms/server/pkg/item" - "github.com/reearth/reearth-cms/server/pkg/key" "github.com/reearth/reearth-cms/server/pkg/model" "github.com/reearth/reearth-cms/server/pkg/schema" "github.com/reearth/reearth-cms/server/pkg/version" @@ -29,7 +28,7 @@ var ( type ItemFieldParam struct { Field *item.FieldID - Key *key.Key + Key *id.Key // Type value.Type Value any Group *id.ItemGroupID diff --git a/server/pkg/exporters/csv_test.go b/server/pkg/exporters/csv_test.go index cfd686d7dc..5319543f56 100644 --- a/server/pkg/exporters/csv_test.go +++ b/server/pkg/exporters/csv_test.go @@ -8,7 +8,6 @@ import ( "github.com/reearth/reearth-cms/server/pkg/id" "github.com/reearth/reearth-cms/server/pkg/item" - "github.com/reearth/reearth-cms/server/pkg/key" "github.com/reearth/reearth-cms/server/pkg/schema" "github.com/reearth/reearth-cms/server/pkg/value" "github.com/reearth/reearth-cms/server/pkg/version" @@ -26,12 +25,12 @@ func TestCSVFromItems(t *testing.T) { pid := id.NewProjectID() gst := schema.GeometryObjectSupportedTypeList{schema.GeometryObjectSupportedTypePoint, schema.GeometryObjectSupportedTypeLineString} gest := schema.GeometryEditorSupportedTypeList{schema.GeometryEditorSupportedTypePoint, schema.GeometryEditorSupportedTypeLineString} - sf1 := schema.NewField(schema.NewGeometryObject(gst).TypeProperty()).NewID().Name("geo1").Key(key.Random()).MustBuild() - sf3 := schema.NewField(schema.NewGeometryEditor(gest).TypeProperty()).NewID().Name("geo2").Key(key.Random()).MustBuild() + sf1 := schema.NewField(schema.NewGeometryObject(gst).TypeProperty()).NewID().Name("geo1").Key(id.RandomKey()).MustBuild() + sf3 := schema.NewField(schema.NewGeometryEditor(gest).TypeProperty()).NewID().Name("geo2").Key(id.RandomKey()).MustBuild() in4, _ := schema.NewInteger(lo.ToPtr(int64(1)), lo.ToPtr(int64(100))) tp4 := in4.TypeProperty() - sf4 := schema.NewField(tp4).NewID().Name("age").Key(key.Random()).MustBuild() - sf5 := schema.NewField(schema.NewBool().TypeProperty()).NewID().Name("isMarried").Key(key.Random()).MustBuild() + sf4 := schema.NewField(tp4).NewID().Name("age").Key(id.RandomKey()).MustBuild() + sf5 := schema.NewField(schema.NewBool().TypeProperty()).NewID().Name("isMarried").Key(id.RandomKey()).MustBuild() s1 := schema.New().ID(sid).Fields([]*schema.Field{sf1, sf3, sf4, sf5}).Workspace(accountdomain.NewWorkspaceID()).Project(pid).MustBuild() fi1 := item.NewField(sf1.ID(), value.TypeGeometryObject.Value("{\"coordinates\":[139.28179282584915,36.58570985749664],\"type\":\"Point\"}").AsMultiple(), nil) fi2 := item.NewField(sf3.ID(), value.TypeGeometryEditor.Value("{\"coordinates\":[139.28179282584915,36.58570985749664],\"type\":\"Point\"}").AsMultiple(), nil) @@ -59,7 +58,7 @@ func TestCSVFromItems(t *testing.T) { sid2 := id.NewSchemaID() mid2 := id.NewModelID() tid2 := id.NewThreadID() - sf2 := schema.NewField(schema.NewText(lo.ToPtr(10)).TypeProperty()).NewID().Key(key.Random()).MustBuild() + sf2 := schema.NewField(schema.NewText(lo.ToPtr(10)).TypeProperty()).NewID().Key(id.RandomKey()).MustBuild() s2 := schema.New().ID(sid).Fields([]*schema.Field{sf2}).Workspace(accountdomain.NewWorkspaceID()).Project(pid).MustBuild() i2 := item.New(). ID(iid2). @@ -83,7 +82,7 @@ func TestCSVFromItems(t *testing.T) { mid3 := id.NewModelID() tid3 := id.NewThreadID() gst2 := schema.GeometryObjectSupportedTypeList{schema.GeometryObjectSupportedTypeLineString, schema.GeometryObjectSupportedTypePolygon} - sf6 := schema.NewField(schema.NewGeometryObject(gst2).TypeProperty()).NewID().Name("geo3").Key(key.Random()).MustBuild() + sf6 := schema.NewField(schema.NewGeometryObject(gst2).TypeProperty()).NewID().Name("geo3").Key(id.RandomKey()).MustBuild() s3 := schema.New().ID(sid).Fields([]*schema.Field{sf6}).Workspace(accountdomain.NewWorkspaceID()).Project(pid).MustBuild() i3 := item.New(). ID(iid3). @@ -107,12 +106,12 @@ func TestBuildCSVHeaders(t *testing.T) { pid := id.NewProjectID() gst := schema.GeometryObjectSupportedTypeList{schema.GeometryObjectSupportedTypePoint, schema.GeometryObjectSupportedTypeLineString} gest := schema.GeometryEditorSupportedTypeList{schema.GeometryEditorSupportedTypePoint, schema.GeometryEditorSupportedTypeLineString} - sf1 := schema.NewField(schema.NewGeometryObject(gst).TypeProperty()).NewID().Name("geo1").Key(key.Random()).MustBuild() - sf2 := schema.NewField(schema.NewGeometryEditor(gest).TypeProperty()).NewID().Name("geo2").Key(key.Random()).MustBuild() + sf1 := schema.NewField(schema.NewGeometryObject(gst).TypeProperty()).NewID().Name("geo1").Key(id.RandomKey()).MustBuild() + sf2 := schema.NewField(schema.NewGeometryEditor(gest).TypeProperty()).NewID().Name("geo2").Key(id.RandomKey()).MustBuild() in4, _ := schema.NewInteger(lo.ToPtr(int64(1)), lo.ToPtr(int64(100))) tp4 := in4.TypeProperty() - sf3 := schema.NewField(tp4).NewID().Name("age").Key(key.Random()).MustBuild() - sf4 := schema.NewField(schema.NewBool().TypeProperty()).NewID().Name("isMarried").Key(key.Random()).MustBuild() + sf3 := schema.NewField(tp4).NewID().Name("age").Key(id.RandomKey()).MustBuild() + sf4 := schema.NewField(schema.NewBool().TypeProperty()).NewID().Name("isMarried").Key(id.RandomKey()).MustBuild() s1 := schema.New().ID(sid).Fields([]*schema.Field{sf1, sf3, sf4}).Workspace(accountdomain.NewWorkspaceID()).Project(pid).MustBuild() s2 := schema.New().ID(sid).Fields([]*schema.Field{sf1, sf2, sf3, sf4}).Workspace(accountdomain.NewWorkspaceID()).Project(pid).MustBuild() @@ -135,12 +134,12 @@ func TestRowFromItem(t *testing.T) { pid := id.NewProjectID() gst := schema.GeometryObjectSupportedTypeList{schema.GeometryObjectSupportedTypePoint, schema.GeometryObjectSupportedTypeLineString} gest := schema.GeometryEditorSupportedTypeList{schema.GeometryEditorSupportedTypePoint, schema.GeometryEditorSupportedTypeLineString} - sf1 := schema.NewField(schema.NewGeometryObject(gst).TypeProperty()).NewID().Name("geo1").Key(key.Random()).MustBuild() - sf2 := schema.NewField(schema.NewGeometryEditor(gest).TypeProperty()).NewID().Name("geo2").Key(key.Random()).MustBuild() + sf1 := schema.NewField(schema.NewGeometryObject(gst).TypeProperty()).NewID().Name("geo1").Key(id.RandomKey()).MustBuild() + sf2 := schema.NewField(schema.NewGeometryEditor(gest).TypeProperty()).NewID().Name("geo2").Key(id.RandomKey()).MustBuild() in4, _ := schema.NewInteger(lo.ToPtr(int64(1)), lo.ToPtr(int64(100))) tp4 := in4.TypeProperty() - sf3 := schema.NewField(tp4).NewID().Name("age").Key(key.Random()).MustBuild() - sf4 := schema.NewField(schema.NewBool().TypeProperty()).NewID().Name("isMarried").Key(key.Random()).MustBuild() + sf3 := schema.NewField(tp4).NewID().Name("age").Key(id.RandomKey()).MustBuild() + sf4 := schema.NewField(schema.NewBool().TypeProperty()).NewID().Name("isMarried").Key(id.RandomKey()).MustBuild() fi1 := item.NewField(sf1.ID(), value.TypeGeometryObject.Value("{\"coordinates\":[139.28179282584915,36.58570985749664],\"type\":\"Point\"}").AsMultiple(), nil) fi2 := item.NewField(sf2.ID(), value.TypeGeometryEditor.Value("{\"coordinates\":[139.28179282584915,36.58570985749664],\"type\":\"Point\"}").AsMultiple(), nil) fi3 := item.NewField(sf3.ID(), value.TypeInteger.Value(30).AsMultiple(), nil) @@ -194,12 +193,12 @@ func TestExtractFirstPointField(t *testing.T) { pid := id.NewProjectID() gst := schema.GeometryObjectSupportedTypeList{schema.GeometryObjectSupportedTypePoint, schema.GeometryObjectSupportedTypeLineString} gest := schema.GeometryEditorSupportedTypeList{schema.GeometryEditorSupportedTypePoint, schema.GeometryEditorSupportedTypeLineString} - sf1 := schema.NewField(schema.NewGeometryObject(gst).TypeProperty()).NewID().Name("geo1").Key(key.Random()).MustBuild() - sf2 := schema.NewField(schema.NewGeometryEditor(gest).TypeProperty()).NewID().Name("geo2").Key(key.Random()).MustBuild() + sf1 := schema.NewField(schema.NewGeometryObject(gst).TypeProperty()).NewID().Name("geo1").Key(id.RandomKey()).MustBuild() + sf2 := schema.NewField(schema.NewGeometryEditor(gest).TypeProperty()).NewID().Name("geo2").Key(id.RandomKey()).MustBuild() in4, _ := schema.NewInteger(lo.ToPtr(int64(1)), lo.ToPtr(int64(100))) tp4 := in4.TypeProperty() - sf3 := schema.NewField(tp4).NewID().Name("age").Key(key.Random()).MustBuild() - sf4 := schema.NewField(schema.NewBool().TypeProperty()).NewID().Name("isMarried").Key(key.Random()).MustBuild() + sf3 := schema.NewField(tp4).NewID().Name("age").Key(id.RandomKey()).MustBuild() + sf4 := schema.NewField(schema.NewBool().TypeProperty()).NewID().Name("isMarried").Key(id.RandomKey()).MustBuild() fi1 := item.NewField(sf1.ID(), value.TypeGeometryObject.Value("{\"coordinates\":[139.28179282584915,36.58570985749664],\"type\":\"Point\"}").AsMultiple(), nil) fi2 := item.NewField(sf2.ID(), value.TypeGeometryEditor.Value("{\"coordinates\": [[[138.90306434425662,36.11737907906834],[138.90306434425662,36.33622175736386],[138.67187898370287,36.33622175736386],[138.67187898370287,36.11737907906834],[138.90306434425662,36.11737907906834]]],\"type\": \"Polygon\"}").AsMultiple(), nil) fi3 := item.NewField(sf3.ID(), value.TypeInteger.Value(30).AsMultiple(), nil) @@ -248,7 +247,7 @@ func TestExtractFirstPointField(t *testing.T) { } func TestToCSVProp(t *testing.T) { - sf1 := schema.NewField(schema.NewText(lo.ToPtr(10)).TypeProperty()).NewID().Key(key.Random()).MustBuild() + sf1 := schema.NewField(schema.NewText(lo.ToPtr(10)).TypeProperty()).NewID().Key(id.RandomKey()).MustBuild() if1 := item.NewField(sf1.ID(), value.TypeText.Value("test").AsMultiple(), nil) s1 := ToCSVProp(if1) assert.Equal(t, "test", s1) @@ -260,21 +259,21 @@ func TestToCSVProp(t *testing.T) { v3 := int64(30) in3, _ := schema.NewInteger(lo.ToPtr(int64(1)), lo.ToPtr(int64(100))) tp3 := in3.TypeProperty() - sf3 := schema.NewField(tp3).NewID().Name("age").Key(key.Random()).MustBuild() + sf3 := schema.NewField(tp3).NewID().Name("age").Key(id.RandomKey()).MustBuild() if3 := item.NewField(sf3.ID(), value.TypeInteger.Value(v3).AsMultiple(), nil) s3, ok3 := ToGeoJsonSingleValue(if3.Value().First()) assert.Equal(t, int64(30), s3) assert.True(t, ok3) v4 := true - sf4 := schema.NewField(schema.NewBool().TypeProperty()).NewID().Name("age").Key(key.Random()).MustBuild() + sf4 := schema.NewField(schema.NewBool().TypeProperty()).NewID().Name("age").Key(id.RandomKey()).MustBuild() if4 := item.NewField(sf4.ID(), value.TypeBool.Value(v4).AsMultiple(), nil) s4, ok4 := ToGeoJsonSingleValue(if4.Value().First()) assert.Equal(t, true, s4) assert.True(t, ok4) v5 := false - sf5 := schema.NewField(schema.NewBool().TypeProperty()).NewID().Name("age").Key(key.Random()).MustBuild() + sf5 := schema.NewField(schema.NewBool().TypeProperty()).NewID().Name("age").Key(id.RandomKey()).MustBuild() if5 := item.NewField(sf5.ID(), value.TypeBool.Value(v5).AsMultiple(), nil) s5, ok5 := ToGeoJsonSingleValue(if5.Value().First()) assert.Equal(t, false, s5) @@ -282,36 +281,36 @@ func TestToCSVProp(t *testing.T) { } func TestToCSVValue(t *testing.T) { - sf1 := schema.NewField(schema.NewText(lo.ToPtr(10)).TypeProperty()).NewID().Key(key.Random()).MustBuild() + sf1 := schema.NewField(schema.NewText(lo.ToPtr(10)).TypeProperty()).NewID().Key(id.RandomKey()).MustBuild() if1 := item.NewField(sf1.ID(), value.TypeText.Value("test").AsMultiple(), nil) s1 := ToCSVValue(if1.Value().First()) assert.Equal(t, "test", s1) - sf2 := schema.NewField(schema.NewTextArea(lo.ToPtr(10)).TypeProperty()).NewID().Key(key.Random()).MustBuild() + sf2 := schema.NewField(schema.NewTextArea(lo.ToPtr(10)).TypeProperty()).NewID().Key(id.RandomKey()).MustBuild() if2 := item.NewField(sf2.ID(), value.TypeTextArea.Value("test").AsMultiple(), nil) s2 := ToCSVValue(if2.Value().First()) assert.Equal(t, "test", s2) - sf3 := schema.NewField(schema.NewURL().TypeProperty()).NewID().Key(key.Random()).MustBuild() + sf3 := schema.NewField(schema.NewURL().TypeProperty()).NewID().Key(id.RandomKey()).MustBuild() v3 := url.URL{Scheme: "https", Host: "reearth.io"} if3 := item.NewField(sf3.ID(), value.TypeURL.Value(v3).AsMultiple(), nil) s3 := ToCSVValue(if3.Value().First()) assert.Equal(t, "https://reearth.io", s3) - sf4 := schema.NewField(schema.NewAsset().TypeProperty()).NewID().Key(key.Random()).MustBuild() + sf4 := schema.NewField(schema.NewAsset().TypeProperty()).NewID().Key(id.RandomKey()).MustBuild() if4 := item.NewField(sf4.ID(), value.TypeAsset.Value(id.NewAssetID()).AsMultiple(), nil) s4 := ToCSVValue(if4.Value().First()) assert.Empty(t, s4) gid := id.NewGroupID() igid := id.NewItemGroupID() - sf5 := schema.NewField(schema.NewGroup(gid).TypeProperty()).NewID().Key(key.Random()).Multiple(true).MustBuild() + sf5 := schema.NewField(schema.NewGroup(gid).TypeProperty()).NewID().Key(id.RandomKey()).Multiple(true).MustBuild() if5 := item.NewField(sf5.ID(), value.MultipleFrom(value.TypeGroup, []*value.Value{value.TypeGroup.Value(igid)}), nil) s5 := ToCSVValue(if5.Value().First()) assert.Empty(t, s5) v6 := id.NewItemID() - sf6 := schema.NewField(schema.NewReference(id.NewModelID(), id.NewSchemaID(), nil, nil).TypeProperty()).NewID().Key(key.Random()).MustBuild() + sf6 := schema.NewField(schema.NewReference(id.NewModelID(), id.NewSchemaID(), nil, nil).TypeProperty()).NewID().Key(id.RandomKey()).MustBuild() if6 := item.NewField(sf6.ID(), value.TypeReference.Value(v6).AsMultiple(), nil) s6 := ToCSVValue(if6.Value().First()) assert.Empty(t, s6) @@ -319,7 +318,7 @@ func TestToCSVValue(t *testing.T) { v7 := int64(30) in7, _ := schema.NewInteger(lo.ToPtr(int64(1)), lo.ToPtr(int64(100))) tp7 := in7.TypeProperty() - sf7 := schema.NewField(tp7).NewID().Name("age").Key(key.Random()).MustBuild() + sf7 := schema.NewField(tp7).NewID().Name("age").Key(id.RandomKey()).MustBuild() if7 := item.NewField(sf7.ID(), value.TypeInteger.Value(v7).AsMultiple(), nil) s7 := ToCSVValue(if7.Value().First()) assert.Equal(t, "30", s7) @@ -327,19 +326,19 @@ func TestToCSVValue(t *testing.T) { v8 := float64(30.123) in8, _ := schema.NewNumber(lo.ToPtr(float64(1)), lo.ToPtr(float64(100))) tp8 := in8.TypeProperty() - sf8 := schema.NewField(tp8).NewID().Name("age").Key(key.Random()).MustBuild() + sf8 := schema.NewField(tp8).NewID().Name("age").Key(id.RandomKey()).MustBuild() if8 := item.NewField(sf8.ID(), value.TypeNumber.Value(v8).AsMultiple(), nil) s8 := ToCSVValue(if8.Value().First()) assert.Equal(t, "30.123", s8) v9 := true - sf9 := schema.NewField(schema.NewBool().TypeProperty()).NewID().Name("age").Key(key.Random()).MustBuild() + sf9 := schema.NewField(schema.NewBool().TypeProperty()).NewID().Name("age").Key(id.RandomKey()).MustBuild() if9 := item.NewField(sf9.ID(), value.TypeBool.Value(v9).AsMultiple(), nil) s9 := ToCSVValue(if9.Value().First()) assert.Equal(t, "true", s9) v10 := time.Now() - sf10 := schema.NewField(schema.NewDateTime().TypeProperty()).NewID().Name("age").Key(key.Random()).MustBuild() + sf10 := schema.NewField(schema.NewDateTime().TypeProperty()).NewID().Name("age").Key(id.RandomKey()).MustBuild() if10 := item.NewField(sf10.ID(), value.TypeDateTime.Value(v10).AsMultiple(), nil) s10 := ToCSVValue(if10.Value().First()) assert.Equal(t, v10.Format(time.RFC3339), s10) diff --git a/server/pkg/exporters/geojson_test.go b/server/pkg/exporters/geojson_test.go index 5308b5c59a..e83fbce5fe 100644 --- a/server/pkg/exporters/geojson_test.go +++ b/server/pkg/exporters/geojson_test.go @@ -8,7 +8,6 @@ import ( "github.com/reearth/reearth-cms/server/pkg/id" "github.com/reearth/reearth-cms/server/pkg/item" - "github.com/reearth/reearth-cms/server/pkg/key" "github.com/reearth/reearth-cms/server/pkg/schema" "github.com/reearth/reearth-cms/server/pkg/value" "github.com/reearth/reearth-cms/server/pkg/version" @@ -28,13 +27,13 @@ func TestFeatureCollectionFromItems(t *testing.T) { pid := id.NewProjectID() gst := schema.GeometryObjectSupportedTypeList{schema.GeometryObjectSupportedTypePoint, schema.GeometryObjectSupportedTypeLineString, schema.GeometryObjectSupportedTypePolygon} gest := schema.GeometryEditorSupportedTypeList{schema.GeometryEditorSupportedTypePoint, schema.GeometryEditorSupportedTypeLineString, schema.GeometryEditorSupportedTypePolygon} - sf1 := schema.NewField(schema.NewGeometryObject(gst).TypeProperty()).NewID().Name("LineString").Key(key.Random()).MustBuild() - sf2 := schema.NewField(schema.NewText(lo.ToPtr(10)).TypeProperty()).NewID().Name("Name").Key(key.Random()).Multiple(true).MustBuild() - sf3 := schema.NewField(schema.NewGeometryEditor(gest).TypeProperty()).NewID().Name("Polygon").Key(key.Random()).MustBuild() + sf1 := schema.NewField(schema.NewGeometryObject(gst).TypeProperty()).NewID().Name("LineString").Key(id.RandomKey()).MustBuild() + sf2 := schema.NewField(schema.NewText(lo.ToPtr(10)).TypeProperty()).NewID().Name("Name").Key(id.RandomKey()).Multiple(true).MustBuild() + sf3 := schema.NewField(schema.NewGeometryEditor(gest).TypeProperty()).NewID().Name("Polygon").Key(id.RandomKey()).MustBuild() in4, _ := schema.NewInteger(lo.ToPtr(int64(1)), lo.ToPtr(int64(100))) tp4 := in4.TypeProperty() - sf4 := schema.NewField(tp4).NewID().Name("Age").Key(key.Random()).MustBuild() - sf5 := schema.NewField(schema.NewBool().TypeProperty()).NewID().Name("IsMarried").Key(key.Random()).MustBuild() + sf4 := schema.NewField(tp4).NewID().Name("Age").Key(id.RandomKey()).MustBuild() + sf5 := schema.NewField(schema.NewBool().TypeProperty()).NewID().Name("IsMarried").Key(id.RandomKey()).MustBuild() fi1 := item.NewField(sf1.ID(), value.TypeGeometryObject.Value("{\"coordinates\":[[139.65439725962517,36.34793305387103],[139.61688622815393,35.910803456352724]],\"type\":\"LineString\"}").AsMultiple(), nil) fi2 := item.NewField(sf2.ID(), value.MultipleFrom(value.TypeText, []*value.Value{value.TypeText.Value("a"), value.TypeText.Value("b"), value.TypeText.Value("c")}), nil) fi3 := item.NewField(sf3.ID(), value.TypeGeometryEditor.Value("{\"coordinates\": [[[138.90306434425662,36.11737907906834],[138.90306434425662,36.33622175736386],[138.67187898370287,36.33622175736386],[138.67187898370287,36.11737907906834],[138.90306434425662,36.11737907906834]]],\"type\": \"Polygon\"}").AsMultiple(), nil) @@ -114,8 +113,8 @@ func TestFeatureCollectionFromItems(t *testing.T) { func TestExtractGeometry(t *testing.T) { gst := schema.GeometryObjectSupportedTypeList{schema.GeometryObjectSupportedTypePoint, schema.GeometryObjectSupportedTypeLineString, schema.GeometryObjectSupportedTypePolygon} - sf1 := schema.NewField(schema.NewGeometryObject(gst).TypeProperty()).NewID().Name("LineString").Key(key.Random()).MustBuild() - sf2 := schema.NewField(schema.NewText(lo.ToPtr(10)).TypeProperty()).NewID().Name("Name").Key(key.Random()).Multiple(true).MustBuild() + sf1 := schema.NewField(schema.NewGeometryObject(gst).TypeProperty()).NewID().Name("LineString").Key(id.RandomKey()).MustBuild() + sf2 := schema.NewField(schema.NewText(lo.ToPtr(10)).TypeProperty()).NewID().Name("Name").Key(id.RandomKey()).Multiple(true).MustBuild() fi1 := item.NewField(sf1.ID(), value.TypeGeometryObject.Value("{\"coordinates\":[[139.65439725962517,36.34793305387103],[139.61688622815393,35.910803456352724]],\"type\":\"LineString\"}").AsMultiple(), nil) fi2 := item.NewField(sf2.ID(), value.MultipleFrom(value.TypeText, []*value.Value{value.TypeText.Value("a"), value.TypeText.Value("b"), value.TypeText.Value("c")}), nil) @@ -141,13 +140,13 @@ func TestExtractProperties(t *testing.T) { pid := id.NewProjectID() gst := schema.GeometryObjectSupportedTypeList{schema.GeometryObjectSupportedTypePoint, schema.GeometryObjectSupportedTypeLineString, schema.GeometryObjectSupportedTypePolygon} gest := schema.GeometryEditorSupportedTypeList{schema.GeometryEditorSupportedTypePoint, schema.GeometryEditorSupportedTypeLineString, schema.GeometryEditorSupportedTypePolygon} - sf1 := schema.NewField(schema.NewGeometryObject(gst).TypeProperty()).NewID().Name("LineString").Key(key.Random()).MustBuild() - sf2 := schema.NewField(schema.NewText(lo.ToPtr(10)).TypeProperty()).NewID().Name("Name").Key(key.Random()).Multiple(true).MustBuild() - sf3 := schema.NewField(schema.NewGeometryEditor(gest).TypeProperty()).NewID().Name("Polygon").Key(key.Random()).MustBuild() + sf1 := schema.NewField(schema.NewGeometryObject(gst).TypeProperty()).NewID().Name("LineString").Key(id.RandomKey()).MustBuild() + sf2 := schema.NewField(schema.NewText(lo.ToPtr(10)).TypeProperty()).NewID().Name("Name").Key(id.RandomKey()).Multiple(true).MustBuild() + sf3 := schema.NewField(schema.NewGeometryEditor(gest).TypeProperty()).NewID().Name("Polygon").Key(id.RandomKey()).MustBuild() in4, _ := schema.NewInteger(lo.ToPtr(int64(1)), lo.ToPtr(int64(100))) tp4 := in4.TypeProperty() - sf4 := schema.NewField(tp4).NewID().Name("Age").Key(key.Random()).MustBuild() - sf5 := schema.NewField(schema.NewBool().TypeProperty()).NewID().Name("IsMarried").Key(key.Random()).MustBuild() + sf4 := schema.NewField(tp4).NewID().Name("Age").Key(id.RandomKey()).MustBuild() + sf5 := schema.NewField(schema.NewBool().TypeProperty()).NewID().Name("IsMarried").Key(id.RandomKey()).MustBuild() fi1 := item.NewField(sf1.ID(), value.TypeGeometryObject.Value("{\"coordinates\":[[139.65439725962517,36.34793305387103],[139.61688622815393,35.910803456352724]],\"type\":\"LineString\"}").AsMultiple(), nil) fi2 := item.NewField(sf2.ID(), value.MultipleFrom(value.TypeText, []*value.Value{value.TypeText.Value("a"), value.TypeText.Value("b"), value.TypeText.Value("c")}), nil) fi3 := item.NewField(sf3.ID(), value.TypeGeometryEditor.Value("{\"coordinates\": [[[138.90306434425662,36.11737907906834],[138.90306434425662,36.33622175736386],[138.67187898370287,36.33622175736386],[138.67187898370287,36.11737907906834],[138.90306434425662,36.11737907906834]]],\"type\": \"Polygon\"}").AsMultiple(), nil) @@ -223,7 +222,7 @@ func TestStringToGeometry(t *testing.T) { } func TestToGeoJSONProp(t *testing.T) { - sf1 := schema.NewField(schema.NewText(lo.ToPtr(10)).TypeProperty()).NewID().Key(key.Random()).MustBuild() + sf1 := schema.NewField(schema.NewText(lo.ToPtr(10)).TypeProperty()).NewID().Key(id.RandomKey()).MustBuild() if1 := item.NewField(sf1.ID(), value.TypeText.Value("test").AsMultiple(), nil) s1, ok1 := ToGeoJSONProp(if1) assert.Equal(t, "test", s1) @@ -234,7 +233,7 @@ func TestToGeoJSONProp(t *testing.T) { assert.Empty(t, s2) assert.False(t, ok2) - sf3 := schema.NewField(schema.NewText(lo.ToPtr(10)).TypeProperty()).NewID().Key(key.Random()).MustBuild() + sf3 := schema.NewField(schema.NewText(lo.ToPtr(10)).TypeProperty()).NewID().Key(id.RandomKey()).MustBuild() if3 := item.NewField(sf3.ID(), value.MultipleFrom(value.TypeText, []*value.Value{value.TypeText.Value("a"), value.TypeText.Value("b"), value.TypeText.Value("c")}), nil) s3, ok3 := ToGeoJSONProp(if3) assert.Equal(t, []any{"a", "b", "c"}, s3) @@ -242,26 +241,26 @@ func TestToGeoJSONProp(t *testing.T) { } func TestToGeoJsonSingleValue(t *testing.T) { - sf1 := schema.NewField(schema.NewText(lo.ToPtr(10)).TypeProperty()).NewID().Key(key.Random()).MustBuild() + sf1 := schema.NewField(schema.NewText(lo.ToPtr(10)).TypeProperty()).NewID().Key(id.RandomKey()).MustBuild() if1 := item.NewField(sf1.ID(), value.TypeText.Value("test").AsMultiple(), nil) s1, ok1 := ToGeoJsonSingleValue(if1.Value().First()) assert.Equal(t, "test", s1) assert.True(t, ok1) - sf2 := schema.NewField(schema.NewTextArea(lo.ToPtr(10)).TypeProperty()).NewID().Key(key.Random()).MustBuild() + sf2 := schema.NewField(schema.NewTextArea(lo.ToPtr(10)).TypeProperty()).NewID().Key(id.RandomKey()).MustBuild() if2 := item.NewField(sf2.ID(), value.TypeTextArea.Value("test").AsMultiple(), nil) s2, ok2 := ToGeoJsonSingleValue(if2.Value().First()) assert.Equal(t, "test", s2) assert.True(t, ok2) - sf3 := schema.NewField(schema.NewURL().TypeProperty()).NewID().Key(key.Random()).MustBuild() + sf3 := schema.NewField(schema.NewURL().TypeProperty()).NewID().Key(id.RandomKey()).MustBuild() v3 := url.URL{Scheme: "https", Host: "reearth.io"} if3 := item.NewField(sf3.ID(), value.TypeURL.Value(v3).AsMultiple(), nil) s3, ok3 := ToGeoJsonSingleValue(if3.Value().First()) assert.Equal(t, "https://reearth.io", s3) assert.True(t, ok3) - sf4 := schema.NewField(schema.NewAsset().TypeProperty()).NewID().Key(key.Random()).MustBuild() + sf4 := schema.NewField(schema.NewAsset().TypeProperty()).NewID().Key(id.RandomKey()).MustBuild() if4 := item.NewField(sf4.ID(), value.TypeAsset.Value(id.NewAssetID()).AsMultiple(), nil) s4, ok4 := ToGeoJsonSingleValue(if4.Value().First()) assert.Empty(t, s4) @@ -269,14 +268,14 @@ func TestToGeoJsonSingleValue(t *testing.T) { gid := id.NewGroupID() igid := id.NewItemGroupID() - sf5 := schema.NewField(schema.NewGroup(gid).TypeProperty()).NewID().Key(key.Random()).Multiple(true).MustBuild() + sf5 := schema.NewField(schema.NewGroup(gid).TypeProperty()).NewID().Key(id.RandomKey()).Multiple(true).MustBuild() if5 := item.NewField(sf5.ID(), value.MultipleFrom(value.TypeGroup, []*value.Value{value.TypeGroup.Value(igid)}), nil) s5, ok5 := ToGeoJsonSingleValue(if5.Value().First()) assert.Empty(t, s5) assert.False(t, ok5) v6 := id.NewItemID() - sf6 := schema.NewField(schema.NewReference(id.NewModelID(), id.NewSchemaID(), nil, nil).TypeProperty()).NewID().Key(key.Random()).MustBuild() + sf6 := schema.NewField(schema.NewReference(id.NewModelID(), id.NewSchemaID(), nil, nil).TypeProperty()).NewID().Key(id.RandomKey()).MustBuild() if6 := item.NewField(sf6.ID(), value.TypeReference.Value(v6).AsMultiple(), nil) s6, ok6 := ToGeoJsonSingleValue(if6.Value().First()) assert.Empty(t, s6) @@ -285,7 +284,7 @@ func TestToGeoJsonSingleValue(t *testing.T) { v7 := int64(30) in7, _ := schema.NewInteger(lo.ToPtr(int64(1)), lo.ToPtr(int64(100))) tp7 := in7.TypeProperty() - sf7 := schema.NewField(tp7).NewID().Name("age").Key(key.Random()).MustBuild() + sf7 := schema.NewField(tp7).NewID().Name("age").Key(id.RandomKey()).MustBuild() if7 := item.NewField(sf7.ID(), value.TypeInteger.Value(v7).AsMultiple(), nil) s7, ok7 := ToGeoJsonSingleValue(if7.Value().First()) assert.Equal(t, int64(30), s7) @@ -294,21 +293,21 @@ func TestToGeoJsonSingleValue(t *testing.T) { v8 := float64(30.123) in8, _ := schema.NewNumber(lo.ToPtr(float64(1)), lo.ToPtr(float64(100))) tp8 := in8.TypeProperty() - sf8 := schema.NewField(tp8).NewID().Name("age").Key(key.Random()).MustBuild() + sf8 := schema.NewField(tp8).NewID().Name("age").Key(id.RandomKey()).MustBuild() if8 := item.NewField(sf8.ID(), value.TypeNumber.Value(v8).AsMultiple(), nil) s8, ok8 := ToGeoJsonSingleValue(if8.Value().First()) assert.Equal(t, 30.123, s8) assert.True(t, ok8) v9 := true - sf9 := schema.NewField(schema.NewBool().TypeProperty()).NewID().Name("age").Key(key.Random()).MustBuild() + sf9 := schema.NewField(schema.NewBool().TypeProperty()).NewID().Name("age").Key(id.RandomKey()).MustBuild() if9 := item.NewField(sf9.ID(), value.TypeBool.Value(v9).AsMultiple(), nil) s9, ok9 := ToGeoJsonSingleValue(if9.Value().First()) assert.Equal(t, true, s9) assert.True(t, ok9) v10 := time.Now() - sf10 := schema.NewField(schema.NewDateTime().TypeProperty()).NewID().Name("age").Key(key.Random()).MustBuild() + sf10 := schema.NewField(schema.NewDateTime().TypeProperty()).NewID().Name("age").Key(id.RandomKey()).MustBuild() if10 := item.NewField(sf10.ID(), value.TypeDateTime.Value(v10).AsMultiple(), nil) s10, ok10 := ToGeoJsonSingleValue(if10.Value().First()) assert.Equal(t, v10.Format(time.RFC3339), s10) diff --git a/server/pkg/group/builder.go b/server/pkg/group/builder.go index 52b4a0e622..7dbbff9a73 100644 --- a/server/pkg/group/builder.go +++ b/server/pkg/group/builder.go @@ -4,7 +4,6 @@ import ( "fmt" "github.com/reearth/reearth-cms/server/pkg/id" - "github.com/reearth/reearth-cms/server/pkg/key" "github.com/reearth/reearthx/rerror" ) @@ -70,7 +69,7 @@ func (b *Builder) Description(description string) *Builder { return b } -func (b *Builder) Key(key key.Key) *Builder { +func (b *Builder) Key(key id.Key) *Builder { b.group.key = key return b } diff --git a/server/pkg/group/builder_test.go b/server/pkg/group/builder_test.go index 3574dd4fad..1c5a5f976a 100644 --- a/server/pkg/group/builder_test.go +++ b/server/pkg/group/builder_test.go @@ -4,7 +4,6 @@ import ( "testing" "github.com/reearth/reearth-cms/server/pkg/id" - "github.com/reearth/reearth-cms/server/pkg/key" "github.com/stretchr/testify/assert" ) @@ -36,7 +35,7 @@ func TestBuilder_Build(t *testing.T) { sId := id.NewSchemaID() type fields struct { m *Group - k key.Key + k id.Key } tests := []struct { name string @@ -53,10 +52,10 @@ func TestBuilder_Build(t *testing.T) { schema: sId, name: "m1", description: "m1 desc", - key: key.New("T123456"), + key: id.NewKey("T123456"), order: 1, }, - k: key.New("T123456"), + k: id.NewKey("T123456"), }, want: &Group{ id: mId, @@ -64,7 +63,7 @@ func TestBuilder_Build(t *testing.T) { schema: sId, name: "m1", description: "m1 desc", - key: key.New("T123456"), + key: id.NewKey("T123456"), order: 1, }, wantErr: nil, @@ -78,10 +77,10 @@ func TestBuilder_Build(t *testing.T) { schema: sId, name: "m1", description: "m1 desc", - key: key.New("T123456"), + key: id.NewKey("T123456"), order: 1, }, - k: key.New("T123456"), + k: id.NewKey("T123456"), }, want: &Group{ id: mId, @@ -89,7 +88,7 @@ func TestBuilder_Build(t *testing.T) { schema: sId, name: "m1", description: "m1 desc", - key: key.New("T123456"), + key: id.NewKey("T123456"), order: 1, }, wantErr: nil, @@ -102,10 +101,10 @@ func TestBuilder_Build(t *testing.T) { schema: sId, name: "m1", description: "m1 desc", - key: key.New("T123456"), + key: id.NewKey("T123456"), order: 1, }, - k: key.New("T123456"), + k: id.NewKey("T123456"), }, want: nil, wantErr: ErrInvalidID, @@ -118,10 +117,10 @@ func TestBuilder_Build(t *testing.T) { project: pId, name: "m1", description: "m1 desc", - key: key.New("T123456"), + key: id.NewKey("T123456"), order: 1, }, - k: key.New("T123456"), + k: id.NewKey("T123456"), }, want: nil, wantErr: ErrInvalidID, @@ -151,7 +150,7 @@ func TestBuilder_MustBuild(t *testing.T) { sId := id.NewSchemaID() type fields struct { m *Group - k key.Key + k id.Key } tests := []struct { name string @@ -168,10 +167,10 @@ func TestBuilder_MustBuild(t *testing.T) { schema: sId, name: "m1", description: "m1 desc", - key: key.New("T123456"), + key: id.NewKey("T123456"), order: 1, }, - k: key.New("T123456"), + k: id.NewKey("T123456"), }, want: &Group{ id: mId, @@ -179,7 +178,7 @@ func TestBuilder_MustBuild(t *testing.T) { schema: sId, name: "m1", description: "m1 desc", - key: key.New("T123456"), + key: id.NewKey("T123456"), order: 1, }, wantErr: nil, @@ -193,10 +192,10 @@ func TestBuilder_MustBuild(t *testing.T) { schema: sId, name: "m1", description: "m1 desc", - key: key.New("T123456"), + key: id.NewKey("T123456"), order: 1, }, - k: key.New("T123456"), + k: id.NewKey("T123456"), }, want: &Group{ id: mId, @@ -204,7 +203,7 @@ func TestBuilder_MustBuild(t *testing.T) { schema: sId, name: "m1", description: "m1 desc", - key: key.New("T123456"), + key: id.NewKey("T123456"), order: 1, }, wantErr: nil, @@ -218,10 +217,10 @@ func TestBuilder_MustBuild(t *testing.T) { schema: sId, name: "m1", description: "m1 desc", - key: key.New("T123456"), + key: id.NewKey("T123456"), order: 1, }, - k: key.New("T123456"), + k: id.NewKey("T123456"), }, want: nil, wantErr: ErrInvalidID, @@ -234,10 +233,10 @@ func TestBuilder_MustBuild(t *testing.T) { project: pId, name: "m1", description: "m1 desc", - key: key.New("T123456"), + key: id.NewKey("T123456"), order: 1, }, - k: key.New("T123456"), + k: id.NewKey("T123456"), }, want: nil, wantErr: ErrInvalidID, @@ -278,7 +277,7 @@ func TestBuilder_ID(t *testing.T) { func TestBuilder_Key(t *testing.T) { b := New() - k := key.New("xabczz") + k := id.NewKey("xabczz") b.Key(k) assert.Equal(t, k, b.group.Key()) } diff --git a/server/pkg/group/group.go b/server/pkg/group/group.go index 6ae62fe1cc..63aad64ecb 100644 --- a/server/pkg/group/group.go +++ b/server/pkg/group/group.go @@ -4,7 +4,6 @@ import ( "fmt" "github.com/reearth/reearth-cms/server/pkg/id" - "github.com/reearth/reearth-cms/server/pkg/key" "github.com/reearth/reearthx/rerror" ) @@ -14,7 +13,7 @@ type Group struct { project ProjectID name string description string - key key.Key + key id.Key order int } @@ -38,7 +37,7 @@ func (g *Group) Description() string { return g.description } -func (g *Group) Key() key.Key { +func (g *Group) Key() id.Key { return g.key } @@ -73,7 +72,7 @@ func (g *Group) SetDescription(des string) { g.description = des } -func (g *Group) SetKey(key key.Key) error { +func (g *Group) SetKey(key id.Key) error { if !validateGroupKey(key) { return &rerror.Error{ Label: id.ErrInvalidKey, @@ -84,6 +83,6 @@ func (g *Group) SetKey(key key.Key) error { return nil } -func validateGroupKey(key key.Key) bool { +func validateGroupKey(key id.Key) bool { return key.IsValid() && len(key.String()) > 2 } diff --git a/server/pkg/group/group_test.go b/server/pkg/group/group_test.go index de7859499f..c872581ae6 100644 --- a/server/pkg/group/group_test.go +++ b/server/pkg/group/group_test.go @@ -5,7 +5,6 @@ import ( "testing" "github.com/reearth/reearth-cms/server/pkg/id" - "github.com/reearth/reearth-cms/server/pkg/key" "github.com/reearth/reearthx/rerror" "github.com/stretchr/testify/assert" ) @@ -26,7 +25,7 @@ func TestGroup_Clone(t *testing.T) { schema: sId, name: "n1", description: "d1", - key: key.New("123456"), + key: id.NewKey("123456"), order: 1, }, }, @@ -111,14 +110,14 @@ func TestGroup_Key(t *testing.T) { tests := []struct { name string group Group - want key.Key + want id.Key }{ { name: "test", group: Group{ - key: key.New("123456"), + key: id.NewKey("123456"), }, - want: key.New("123456"), + want: id.NewKey("123456"), }, } for _, tt := range tests { @@ -238,7 +237,7 @@ func TestGroup_SetDescription(t *testing.T) { func TestGroup_SetKey(t *testing.T) { type args struct { - key key.Key + key id.Key } tests := []struct { name string @@ -248,40 +247,40 @@ func TestGroup_SetKey(t *testing.T) { }{ { name: "pass", - args: args{key: key.New("123456")}, - want: Group{key: key.New("123456")}, + args: args{key: id.NewKey("123456")}, + want: Group{key: id.NewKey("123456")}, wantErr: nil, }, { name: "fail", - args: args{key: key.New("a")}, + args: args{key: id.NewKey("a")}, want: Group{}, wantErr: &rerror.Error{ Label: id.ErrInvalidKey, Err: fmt.Errorf("%s", "a"), }, }, - { - name: "fail 2", - args: args{key: key.New("_aaaaaaaa")}, - want: Group{}, - wantErr: &rerror.Error{ - Label: id.ErrInvalidKey, - Err: fmt.Errorf("%s", "_aaaaaaaa"), - }, - }, - { - name: "fail 3", - args: args{key: key.New("-aaaaaaaa")}, - want: Group{}, - wantErr: &rerror.Error{ - Label: id.ErrInvalidKey, - Err: fmt.Errorf("%s", "-aaaaaaaa"), - }, - }, + //{ + // name: "fail 2", + // args: args{key: id.NewKey("_aaaaaaaa")}, + // want: Group{}, + // wantErr: &rerror.Error{ + // Label: id.ErrInvalidKey, + // Err: fmt.Errorf("%s", "_aaaaaaaa"), + // }, + //}, + //{ + // name: "fail 3", + // args: args{key: id.NewKey("-aaaaaaaa")}, + // want: Group{}, + // wantErr: &rerror.Error{ + // Label: id.ErrInvalidKey, + // Err: fmt.Errorf("%s", "-aaaaaaaa"), + // }, + //}, { name: "empty", - args: args{key: key.New("")}, + args: args{key: id.NewKey("")}, want: Group{}, wantErr: &rerror.Error{ Label: id.ErrInvalidKey, diff --git a/server/pkg/group/list_test.go b/server/pkg/group/list_test.go index d1d7ab419b..6b2c929851 100644 --- a/server/pkg/group/list_test.go +++ b/server/pkg/group/list_test.go @@ -4,7 +4,6 @@ import ( "testing" "github.com/reearth/reearth-cms/server/pkg/id" - "github.com/reearth/reearth-cms/server/pkg/key" "github.com/stretchr/testify/assert" ) @@ -45,9 +44,9 @@ func TestList_OrderByIDs(t *testing.T) { sid1 := id.NewSchemaID() sid2 := id.NewSchemaID() sid3 := id.NewSchemaID() - group1 := New().NewID().Project(pid).Schema(sid1).Key(key.New("key1")).Order(0).MustBuild() - group2 := New().NewID().Project(pid).Schema(sid2).Key(key.New("key2")).Order(0).MustBuild() - group3 := New().NewID().Project(pid).Schema(sid3).Key(key.New("key3")).Order(0).MustBuild() + group1 := New().NewID().Project(pid).Schema(sid1).Key(id.NewKey("key1")).Order(0).MustBuild() + group2 := New().NewID().Project(pid).Schema(sid2).Key(id.NewKey("key2")).Order(0).MustBuild() + group3 := New().NewID().Project(pid).Schema(sid3).Key(id.NewKey("key3")).Order(0).MustBuild() groups := List{group1, group2, group3} assert.Equal(t, List{group2, group1, group3}, groups.OrderByIDs(id.GroupIDList{group2.ID(), group1.ID(), group3.ID()})) assert.Equal(t, id.ProjectIDList{pid, pid, pid}, groups.Projects()) @@ -55,9 +54,9 @@ func TestList_OrderByIDs(t *testing.T) { func TestList_Ordered(t *testing.T) { pid := id.NewProjectID() - g1 := New().NewID().Project(pid).Schema(id.NewSchemaID()).Key(key.New("key1")).Order(0).MustBuild() - g2 := New().NewID().Project(pid).Schema(id.NewSchemaID()).Key(key.New("key2")).Order(1).MustBuild() - g3 := New().NewID().Project(pid).Schema(id.NewSchemaID()).Key(key.New("key3")).Order(2).MustBuild() + g1 := New().NewID().Project(pid).Schema(id.NewSchemaID()).Key(id.NewKey("key1")).Order(0).MustBuild() + g2 := New().NewID().Project(pid).Schema(id.NewSchemaID()).Key(id.NewKey("key2")).Order(1).MustBuild() + g3 := New().NewID().Project(pid).Schema(id.NewSchemaID()).Key(id.NewKey("key3")).Order(2).MustBuild() groups := List{g3, g1, g2} ordered := groups.Ordered() assert.NotEqual(t, groups, ordered) diff --git a/server/pkg/id/key.go b/server/pkg/id/key.go index ab101c2729..5daf3a1a97 100644 --- a/server/pkg/id/key.go +++ b/server/pkg/id/key.go @@ -1,15 +1,14 @@ package id import ( - "github.com/reearth/reearthx/i18n" - "github.com/reearth/reearthx/rerror" "regexp" - "strings" + "slices" "github.com/goombaio/namegenerator" + "github.com/reearth/reearthx/i18n" + "github.com/reearth/reearthx/rerror" "github.com/reearth/reearthx/util" "github.com/samber/lo" - "golang.org/x/exp/slices" ) var ErrInvalidKey = rerror.NewE(i18n.T("invalid key")) @@ -25,9 +24,6 @@ type Key struct { } func NewKey(key string) Key { - if !keyRegexp.MatchString(key) { - return Key{} - } k := Key{key} return k } @@ -42,7 +38,11 @@ func RandomKey() Key { } func (k Key) IsValid() bool { - return k.key != "" && !strings.HasPrefix(k.key, "_") && !strings.HasPrefix(k.key, "-") && !slices.Contains(ngKeys, k.key) + return k.key != "" && !slices.Contains(ngKeys, k.key) // && !strings.HasPrefix(k.key, "_") && !strings.HasPrefix(k.key, "-") +} + +func (k Key) IsURLCompatible() bool { + return k.IsValid() && keyRegexp.MatchString(k.key) } func (k Key) Ref() *Key { diff --git a/server/pkg/id/key_test.go b/server/pkg/id/key_test.go index 6673187088..fcddc667fc 100644 --- a/server/pkg/id/key_test.go +++ b/server/pkg/id/key_test.go @@ -10,7 +10,8 @@ import ( func TestNewKey(t *testing.T) { assert.Equal(t, Key{key: "aaaaaaa"}, NewKey("aaaaaaa")) assert.Equal(t, Key{key: "aaaa"}, NewKey("aaaa")) - assert.Equal(t, Key{}, NewKey("aaa!@#")) + assert.Equal(t, Key{key: "aaa!@#"}, NewKey("aaa!@#")) + assert.Equal(t, Key{key: "テスト"}, NewKey("テスト")) } func TestRandomKey(t *testing.T) { @@ -25,6 +26,14 @@ func TestKey_IsValid(t *testing.T) { assert.False(t, Key{key: "id"}.IsValid()) } +func TestKey_IsURLCompatible(t *testing.T) { + assert.True(t, Key{key: "aaa"}.IsURLCompatible()) + assert.False(t, Key{}.IsURLCompatible()) + assert.False(t, Key{key: "id"}.IsURLCompatible()) + assert.False(t, Key{key: "#aaa"}.IsURLCompatible()) + assert.False(t, Key{key: "a b"}.IsURLCompatible()) +} + func TestKey_Ref(t *testing.T) { assert.Equal(t, lo.ToPtr(Key{key: "aaa"}), Key{key: "aaa"}.Ref()) } diff --git a/server/pkg/item/item_test.go b/server/pkg/item/item_test.go index 78b4de5575..9b8dced53b 100644 --- a/server/pkg/item/item_test.go +++ b/server/pkg/item/item_test.go @@ -5,7 +5,6 @@ import ( "time" "github.com/reearth/reearth-cms/server/pkg/id" - "github.com/reearth/reearth-cms/server/pkg/key" "github.com/reearth/reearth-cms/server/pkg/schema" "github.com/reearth/reearth-cms/server/pkg/value" "github.com/reearth/reearthx/account/accountdomain" @@ -266,8 +265,8 @@ func TestItem_SetOriginalItem(t *testing.T) { func TestItem_GetTitle(t *testing.T) { wid := accountdomain.NewWorkspaceID() pid := id.NewProjectID() - sf1 := schema.NewField(schema.NewBool().TypeProperty()).NewID().Key(key.Random()).MustBuild() - sf2 := schema.NewField(schema.NewText(lo.ToPtr(10)).TypeProperty()).NewID().Key(key.Random()).MustBuild() + sf1 := schema.NewField(schema.NewBool().TypeProperty()).NewID().Key(id.RandomKey()).MustBuild() + sf2 := schema.NewField(schema.NewText(lo.ToPtr(10)).TypeProperty()).NewID().Key(id.RandomKey()).MustBuild() s1 := schema.New().NewID().Workspace(wid).Project(pid).Fields(schema.FieldList{sf1, sf2}).MustBuild() if1 := NewField(sf1.ID(), value.TypeBool.Value(false).AsMultiple(), nil) if2 := NewField(sf2.ID(), value.TypeText.Value("test").AsMultiple(), nil) @@ -300,13 +299,13 @@ func TestGetFirstGeometryField(t *testing.T) { pid := id.NewProjectID() gst := schema.GeometryObjectSupportedTypeList{schema.GeometryObjectSupportedTypePoint, schema.GeometryObjectSupportedTypeLineString, schema.GeometryObjectSupportedTypePolygon} gest := schema.GeometryEditorSupportedTypeList{schema.GeometryEditorSupportedTypePoint, schema.GeometryEditorSupportedTypeLineString, schema.GeometryEditorSupportedTypePolygon} - sf1 := schema.NewField(schema.NewGeometryObject(gst).TypeProperty()).NewID().Name("LineString").Key(key.Random()).MustBuild() - sf2 := schema.NewField(schema.NewText(lo.ToPtr(10)).TypeProperty()).NewID().Name("Name").Key(key.Random()).Multiple(true).MustBuild() - sf3 := schema.NewField(schema.NewGeometryEditor(gest).TypeProperty()).NewID().Name("Polygon").Key(key.Random()).MustBuild() + sf1 := schema.NewField(schema.NewGeometryObject(gst).TypeProperty()).NewID().Name("LineString").Key(id.RandomKey()).MustBuild() + sf2 := schema.NewField(schema.NewText(lo.ToPtr(10)).TypeProperty()).NewID().Name("Name").Key(id.RandomKey()).Multiple(true).MustBuild() + sf3 := schema.NewField(schema.NewGeometryEditor(gest).TypeProperty()).NewID().Name("Polygon").Key(id.RandomKey()).MustBuild() in4, _ := schema.NewInteger(lo.ToPtr(int64(1)), lo.ToPtr(int64(100))) tp4 := in4.TypeProperty() - sf4 := schema.NewField(tp4).NewID().Name("Age").Key(key.Random()).MustBuild() - sf5 := schema.NewField(schema.NewBool().TypeProperty()).NewID().Name("IsMarried").Key(key.Random()).MustBuild() + sf4 := schema.NewField(tp4).NewID().Name("Age").Key(id.RandomKey()).MustBuild() + sf5 := schema.NewField(schema.NewBool().TypeProperty()).NewID().Name("IsMarried").Key(id.RandomKey()).MustBuild() fi1 := NewField(sf1.ID(), value.TypeGeometryObject.Value("{\"coordinates\":[[139.65439725962517,36.34793305387103],[139.61688622815393,35.910803456352724]],\"type\":\"LineString\"}").AsMultiple(), nil) fi2 := NewField(sf2.ID(), value.MultipleFrom(value.TypeText, []*value.Value{value.TypeText.Value("a"), value.TypeText.Value("b"), value.TypeText.Value("c")}), nil) fi3 := NewField(sf3.ID(), value.TypeGeometryEditor.Value("{\"coordinates\": [[[138.90306434425662,36.11737907906834],[138.90306434425662,36.33622175736386],[138.67187898370287,36.33622175736386],[138.67187898370287,36.11737907906834],[138.90306434425662,36.11737907906834]]],\"type\": \"Polygon\"}").AsMultiple(), nil) diff --git a/server/pkg/item/reference_test.go b/server/pkg/item/reference_test.go index 8a888f0260..43cda453e8 100644 --- a/server/pkg/item/reference_test.go +++ b/server/pkg/item/reference_test.go @@ -4,7 +4,6 @@ import ( "testing" "github.com/reearth/reearth-cms/server/pkg/id" - "github.com/reearth/reearth-cms/server/pkg/key" "github.com/reearth/reearth-cms/server/pkg/project" "github.com/reearth/reearth-cms/server/pkg/schema" "github.com/reearth/reearth-cms/server/pkg/value" @@ -29,9 +28,9 @@ func Test_AreItemsReferenced(t *testing.T) { Description: "description", Required: true, } - f1 := schema.NewField(schema.NewReference(mid2, sid1, fid2.Ref(), cf1).TypeProperty()).ID(fid1).Key(key.Random()).MustBuild() - f2 := schema.NewField(schema.NewReference(mid1, sid2, fid1.Ref(), cf2).TypeProperty()).ID(fid2).Key(key.Random()).MustBuild() - f3 := schema.NewField(schema.NewReference(mid3, sid3, nil, nil).TypeProperty()).ID(fid3).Key(key.Random()).MustBuild() + f1 := schema.NewField(schema.NewReference(mid2, sid1, fid2.Ref(), cf1).TypeProperty()).ID(fid1).Key(id.RandomKey()).MustBuild() + f2 := schema.NewField(schema.NewReference(mid1, sid2, fid1.Ref(), cf2).TypeProperty()).ID(fid2).Key(id.RandomKey()).MustBuild() + f3 := schema.NewField(schema.NewReference(mid3, sid3, nil, nil).TypeProperty()).ID(fid3).Key(id.RandomKey()).MustBuild() s1 := schema.New().ID(sid1).Workspace(accountdomain.NewWorkspaceID()).Project(prj.ID()).Fields(schema.FieldList{f1}).MustBuild() s2 := schema.New().ID(sid2).Workspace(accountdomain.NewWorkspaceID()).Project(prj.ID()).Fields(schema.FieldList{f2}).MustBuild() s3 := schema.New().ID(sid3).Workspace(accountdomain.NewWorkspaceID()).Project(prj.ID()).Fields(schema.FieldList{f3}).MustBuild() diff --git a/server/pkg/key/key.go b/server/pkg/key/key.go deleted file mode 100644 index eaff312935..0000000000 --- a/server/pkg/key/key.go +++ /dev/null @@ -1,11 +0,0 @@ -package key - -import ( - "github.com/reearth/reearth-cms/server/pkg/id" -) - -// TODO: completely delete this "key" package -type Key = id.Key - -var New = id.NewKey -var Random = id.RandomKey diff --git a/server/pkg/model/builder.go b/server/pkg/model/builder.go index 1efc169c0b..7b52dc1c4b 100644 --- a/server/pkg/model/builder.go +++ b/server/pkg/model/builder.go @@ -4,12 +4,11 @@ import ( "time" "github.com/reearth/reearth-cms/server/pkg/id" - "github.com/reearth/reearth-cms/server/pkg/key" ) type Builder struct { model *Model - k key.Key + k id.Key } func New() *Builder { @@ -75,13 +74,13 @@ func (b *Builder) Description(description string) *Builder { return b } -func (b *Builder) Key(key key.Key) *Builder { +func (b *Builder) Key(key id.Key) *Builder { b.k = key return b } func (b *Builder) RandomKey() *Builder { - b.k = key.Random() + b.k = id.RandomKey() return b } diff --git a/server/pkg/model/builder_test.go b/server/pkg/model/builder_test.go index 6258af6440..edee5a1a2f 100644 --- a/server/pkg/model/builder_test.go +++ b/server/pkg/model/builder_test.go @@ -6,7 +6,6 @@ import ( "time" "github.com/reearth/reearth-cms/server/pkg/id" - "github.com/reearth/reearth-cms/server/pkg/key" "github.com/reearth/reearthx/rerror" "github.com/stretchr/testify/assert" ) @@ -20,7 +19,7 @@ func TestNew(t *testing.T) { name: "test", want: &Builder{ model: &Model{}, - k: key.Key{}, + k: id.Key{}, }, }, } @@ -41,7 +40,7 @@ func TestBuilder_Build(t *testing.T) { now := time.Now() type fields struct { m *Model - k key.Key + k id.Key } tests := []struct { name string @@ -58,12 +57,12 @@ func TestBuilder_Build(t *testing.T) { schema: sId, name: "m1", description: "m1 desc", - key: key.New("T123456"), + key: id.NewKey("T123456"), public: false, updatedAt: now, order: 2, }, - k: key.New("T123456"), + k: id.NewKey("T123456"), }, want: &Model{ id: mId, @@ -71,7 +70,7 @@ func TestBuilder_Build(t *testing.T) { schema: sId, name: "m1", description: "m1 desc", - key: key.New("T123456"), + key: id.NewKey("T123456"), public: false, updatedAt: now, order: 2, @@ -87,11 +86,11 @@ func TestBuilder_Build(t *testing.T) { schema: sId, name: "m1", description: "m1 desc", - key: key.New("T123456"), + key: id.NewKey("T123456"), public: false, // updatedAt: now, }, - k: key.New("T123456"), + k: id.NewKey("T123456"), }, want: &Model{ id: mId, @@ -99,7 +98,7 @@ func TestBuilder_Build(t *testing.T) { schema: sId, name: "m1", description: "m1 desc", - key: key.New("T123456"), + key: id.NewKey("T123456"), public: false, updatedAt: mId.Timestamp(), }, @@ -114,11 +113,11 @@ func TestBuilder_Build(t *testing.T) { schema: sId, name: "m1", description: "m1 desc", - key: key.New("T123456"), + key: id.NewKey("T123456"), public: false, updatedAt: now, }, - k: key.New("T123456"), + k: id.NewKey("T123456"), }, want: nil, wantErr: ErrInvalidID, @@ -132,11 +131,11 @@ func TestBuilder_Build(t *testing.T) { // schema: sId, name: "m1", description: "m1 desc", - key: key.New("T123456"), + key: id.NewKey("T123456"), public: false, updatedAt: now, }, - k: key.New("T123456"), + k: id.NewKey("T123456"), }, want: nil, wantErr: ErrInvalidID, @@ -150,7 +149,7 @@ func TestBuilder_Build(t *testing.T) { schema: sId, name: "m1", description: "m1 desc", - key: key.New("T123456"), + key: id.NewKey("T123456"), public: false, updatedAt: now, }, @@ -189,7 +188,7 @@ func TestBuilder_MustBuild(t *testing.T) { now := time.Now() type fields struct { m *Model - k key.Key + k id.Key } tests := []struct { name string @@ -206,11 +205,11 @@ func TestBuilder_MustBuild(t *testing.T) { schema: sId, name: "m1", description: "m1 desc", - key: key.New("T123456"), + key: id.NewKey("T123456"), public: false, updatedAt: now, }, - k: key.New("T123456"), + k: id.NewKey("T123456"), }, want: &Model{ id: mId, @@ -218,7 +217,7 @@ func TestBuilder_MustBuild(t *testing.T) { schema: sId, name: "m1", description: "m1 desc", - key: key.New("T123456"), + key: id.NewKey("T123456"), public: false, updatedAt: now, }, @@ -233,11 +232,11 @@ func TestBuilder_MustBuild(t *testing.T) { schema: sId, name: "m1", description: "m1 desc", - key: key.New("T123456"), + key: id.NewKey("T123456"), public: false, // updatedAt: now, }, - k: key.New("T123456"), + k: id.NewKey("T123456"), }, want: &Model{ id: mId, @@ -245,7 +244,7 @@ func TestBuilder_MustBuild(t *testing.T) { schema: sId, name: "m1", description: "m1 desc", - key: key.New("T123456"), + key: id.NewKey("T123456"), public: false, updatedAt: mId.Timestamp(), }, @@ -260,11 +259,11 @@ func TestBuilder_MustBuild(t *testing.T) { schema: sId, name: "m1", description: "m1 desc", - key: key.New("T123456"), + key: id.NewKey("T123456"), public: false, updatedAt: now, }, - k: key.New("T123456"), + k: id.NewKey("T123456"), }, want: nil, wantErr: ErrInvalidID, @@ -278,11 +277,11 @@ func TestBuilder_MustBuild(t *testing.T) { // schema: sId, name: "m1", description: "m1 desc", - key: key.New("T123456"), + key: id.NewKey("T123456"), public: false, updatedAt: now, }, - k: key.New("T123456"), + k: id.NewKey("T123456"), }, want: nil, wantErr: ErrInvalidID, @@ -296,7 +295,7 @@ func TestBuilder_MustBuild(t *testing.T) { schema: sId, name: "m1", description: "m1 desc", - key: key.New("T123456"), + key: id.NewKey("T123456"), public: false, updatedAt: now, }, @@ -333,7 +332,7 @@ func TestBuilder_MustBuild(t *testing.T) { func TestBuilder_Description(t *testing.T) { type fields struct { model *Model - k key.Key + k id.Key } type args struct { description string @@ -348,7 +347,7 @@ func TestBuilder_Description(t *testing.T) { name: "test", fields: fields{ model: &Model{}, - k: key.Key{}, + k: id.Key{}, }, args: args{ description: "d1", @@ -357,7 +356,7 @@ func TestBuilder_Description(t *testing.T) { model: &Model{ description: "d1", }, - k: key.Key{}, + k: id.Key{}, }, }, } @@ -379,7 +378,7 @@ func TestBuilder_ID(t *testing.T) { mId := NewID() type fields struct { model *Model - k key.Key + k id.Key } type args struct { id ID @@ -394,7 +393,7 @@ func TestBuilder_ID(t *testing.T) { name: "test", fields: fields{ model: &Model{}, - k: key.Key{}, + k: id.Key{}, }, args: args{ id: mId, @@ -403,7 +402,7 @@ func TestBuilder_ID(t *testing.T) { model: &Model{ id: mId, }, - k: key.Key{}, + k: id.Key{}, }, }, } @@ -424,7 +423,7 @@ func TestBuilder_ID(t *testing.T) { func TestBuilder_Public(t *testing.T) { type fields struct { model *Model - k key.Key + k id.Key } type args struct { public bool @@ -439,7 +438,7 @@ func TestBuilder_Public(t *testing.T) { name: "test 1", fields: fields{ model: &Model{}, - k: key.Key{}, + k: id.Key{}, }, args: args{ public: true, @@ -448,14 +447,14 @@ func TestBuilder_Public(t *testing.T) { model: &Model{ public: true, }, - k: key.Key{}, + k: id.Key{}, }, }, { name: "test 2", fields: fields{ model: &Model{}, - k: key.Key{}, + k: id.Key{}, }, args: args{ public: false, @@ -464,7 +463,7 @@ func TestBuilder_Public(t *testing.T) { model: &Model{ public: false, }, - k: key.Key{}, + k: id.Key{}, }, }, } @@ -485,10 +484,10 @@ func TestBuilder_Public(t *testing.T) { func TestBuilder_Key(t *testing.T) { type fields struct { model *Model - k key.Key + k id.Key } type args struct { - key key.Key + key id.Key } tests := []struct { name string @@ -500,14 +499,14 @@ func TestBuilder_Key(t *testing.T) { name: "test 1", fields: fields{ model: &Model{}, - k: key.Key{}, + k: id.Key{}, }, args: args{ - key: key.New("123321"), + key: id.NewKey("123321"), }, want: &Builder{ model: &Model{}, - k: key.New("123321"), + k: id.NewKey("123321"), }, }, } @@ -528,7 +527,7 @@ func TestBuilder_Key(t *testing.T) { func TestBuilder_Name(t *testing.T) { type fields struct { model *Model - k key.Key + k id.Key } type args struct { name string @@ -543,7 +542,7 @@ func TestBuilder_Name(t *testing.T) { name: "test", fields: fields{ model: &Model{}, - k: key.Key{}, + k: id.Key{}, }, args: args{ name: "n1", @@ -552,7 +551,7 @@ func TestBuilder_Name(t *testing.T) { model: &Model{ name: "n1", }, - k: key.Key{}, + k: id.Key{}, }, }, } @@ -573,7 +572,7 @@ func TestBuilder_Name(t *testing.T) { func TestBuilder_NewID(t *testing.T) { type fields struct { p *Model - k key.Key + k id.Key } tests := []struct { name string @@ -583,7 +582,7 @@ func TestBuilder_NewID(t *testing.T) { name: "test", fields: fields{ p: &Model{}, - k: key.Key{}, + k: id.Key{}, }, }, } @@ -606,7 +605,7 @@ func TestBuilder_Project(t *testing.T) { pId := id.NewProjectID() type fields struct { model *Model - k key.Key + k id.Key } type args struct { p id.ProjectID @@ -621,7 +620,7 @@ func TestBuilder_Project(t *testing.T) { name: "test", fields: fields{ model: &Model{}, - k: key.Key{}, + k: id.Key{}, }, args: args{ p: pId, @@ -630,7 +629,7 @@ func TestBuilder_Project(t *testing.T) { model: &Model{ project: pId, }, - k: key.Key{}, + k: id.Key{}, }, }, } @@ -651,7 +650,7 @@ func TestBuilder_Project(t *testing.T) { func TestBuilder_RandomKey(t *testing.T) { type fields struct { p *Model - k key.Key + k id.Key } tests := []struct { name string @@ -661,7 +660,7 @@ func TestBuilder_RandomKey(t *testing.T) { name: "test", fields: fields{ p: &Model{}, - k: key.Key{}, + k: id.Key{}, }, }, } @@ -684,7 +683,7 @@ func TestBuilder_Schema(t *testing.T) { sId := id.NewSchemaID() type fields struct { model *Model - k key.Key + k id.Key } type args struct { s id.SchemaID @@ -699,7 +698,7 @@ func TestBuilder_Schema(t *testing.T) { name: "test", fields: fields{ model: &Model{}, - k: key.Key{}, + k: id.Key{}, }, args: args{ s: sId, @@ -708,7 +707,7 @@ func TestBuilder_Schema(t *testing.T) { model: &Model{ schema: sId, }, - k: key.Key{}, + k: id.Key{}, }, }, } @@ -730,7 +729,7 @@ func TestBuilder_UpdatedAt(t *testing.T) { now := time.Now() type fields struct { model *Model - k key.Key + k id.Key } type args struct { updatedAt time.Time @@ -745,7 +744,7 @@ func TestBuilder_UpdatedAt(t *testing.T) { name: "test", fields: fields{ model: &Model{}, - k: key.Key{}, + k: id.Key{}, }, args: args{ updatedAt: now, @@ -754,7 +753,7 @@ func TestBuilder_UpdatedAt(t *testing.T) { model: &Model{ updatedAt: now, }, - k: key.Key{}, + k: id.Key{}, }, }, } diff --git a/server/pkg/model/list_test.go b/server/pkg/model/list_test.go index d2c2cda34a..6eda6eed11 100644 --- a/server/pkg/model/list_test.go +++ b/server/pkg/model/list_test.go @@ -4,8 +4,6 @@ import ( "testing" "github.com/reearth/reearth-cms/server/pkg/id" - "github.com/reearth/reearth-cms/server/pkg/key" - "github.com/stretchr/testify/assert" ) @@ -46,9 +44,9 @@ func TestList_OrderByIDs(t *testing.T) { sid1 := id.NewSchemaID() sid2 := id.NewSchemaID() sid3 := id.NewSchemaID() - mod1 := New().NewID().Project(pid).Schema(sid1).Key(key.New("key1")).Order(0).MustBuild() - mod2 := New().NewID().Project(pid).Schema(sid2).Key(key.New("key2")).Order(0).MustBuild() - mod3 := New().NewID().Project(pid).Schema(sid3).Key(key.New("key3")).Order(0).MustBuild() + mod1 := New().NewID().Project(pid).Schema(sid1).Key(id.NewKey("key1")).Order(0).MustBuild() + mod2 := New().NewID().Project(pid).Schema(sid2).Key(id.NewKey("key2")).Order(0).MustBuild() + mod3 := New().NewID().Project(pid).Schema(sid3).Key(id.NewKey("key3")).Order(0).MustBuild() mods := List{mod1, mod2, mod3} assert.Equal(t, List{mod2, mod1, mod3}, mods.OrderByIDs(id.ModelIDList{mod2.ID(), mod1.ID(), mod3.ID()})) assert.Equal(t, id.ProjectIDList{pid}, mods.Projects()) @@ -59,9 +57,9 @@ func TestList_Remove(t *testing.T) { sid1 := id.NewSchemaID() sid2 := id.NewSchemaID() sid3 := id.NewSchemaID() - mod1 := New().NewID().Project(pid).Schema(sid1).Key(key.New("key1")).Order(0).MustBuild() - mod2 := New().NewID().Project(pid).Schema(sid2).Key(key.New("key2")).Order(1).MustBuild() - mod3 := New().NewID().Project(pid).Schema(sid3).Key(key.New("key3")).Order(2).MustBuild() + mod1 := New().NewID().Project(pid).Schema(sid1).Key(id.NewKey("key1")).Order(0).MustBuild() + mod2 := New().NewID().Project(pid).Schema(sid2).Key(id.NewKey("key2")).Order(1).MustBuild() + mod3 := New().NewID().Project(pid).Schema(sid3).Key(id.NewKey("key3")).Order(2).MustBuild() mods := List{mod1, mod2, mod3} assert.Equal(t, List{mod1, mod3}, mods.Remove(mod2.ID())) assert.Equal(t, List{mod1, mod2}, mods.Remove(mod3.ID())) @@ -70,12 +68,11 @@ func TestList_Remove(t *testing.T) { func TestList_Ordered(t *testing.T) { pid := id.NewProjectID() - m1 := New().NewID().Project(pid).Schema(id.NewSchemaID()).Key(key.New("key1")).Order(0).MustBuild() - m2 := New().NewID().Project(pid).Schema(id.NewSchemaID()).Key(key.New("key2")).Order(1).MustBuild() - m3 := New().NewID().Project(pid).Schema(id.NewSchemaID()).Key(key.New("key3")).Order(2).MustBuild() + m1 := New().NewID().Project(pid).Schema(id.NewSchemaID()).Key(id.NewKey("key1")).Order(0).MustBuild() + m2 := New().NewID().Project(pid).Schema(id.NewSchemaID()).Key(id.NewKey("key2")).Order(1).MustBuild() + m3 := New().NewID().Project(pid).Schema(id.NewSchemaID()).Key(id.NewKey("key3")).Order(2).MustBuild() models := List{m3, m1, m2} ordered := models.Ordered() assert.NotEqual(t, models, ordered) assert.Equal(t, List{m1, m2, m3}, ordered) } - diff --git a/server/pkg/model/model.go b/server/pkg/model/model.go index 3a1ef10b96..ccd70aeb65 100644 --- a/server/pkg/model/model.go +++ b/server/pkg/model/model.go @@ -2,10 +2,10 @@ package model import ( "fmt" - "github.com/reearth/reearth-cms/server/pkg/id" "time" - "github.com/reearth/reearth-cms/server/pkg/key" + "github.com/reearth/reearth-cms/server/pkg/id" + "github.com/reearth/reearthx/i18n" "github.com/reearth/reearthx/rerror" "golang.org/x/exp/slices" @@ -23,7 +23,7 @@ type Model struct { metadata *SchemaID name string description string - key key.Key + key id.Key public bool updatedAt time.Time order int @@ -65,11 +65,11 @@ func (p *Model) SetDescription(description string) { p.description = description } -func (p *Model) Key() key.Key { +func (p *Model) Key() id.Key { return p.key } -func (p *Model) SetKey(key key.Key) error { +func (p *Model) SetKey(key id.Key) error { if !validateModelKey(key) { return &rerror.Error{ Label: ErrInvalidKey, @@ -129,7 +129,7 @@ func (p *Model) Clone() *Model { } } -func validateModelKey(k key.Key) bool { +func validateModelKey(k id.Key) bool { // assets is used as an API endpoint - return k.IsValid() && len(k.String()) > 2 && !slices.Contains(ngKeys, k.String()) + return k.IsURLCompatible() && len(k.String()) > 2 && !slices.Contains(ngKeys, k.String()) } diff --git a/server/pkg/model/model_test.go b/server/pkg/model/model_test.go index 7b17f97c5e..fa24371f8e 100644 --- a/server/pkg/model/model_test.go +++ b/server/pkg/model/model_test.go @@ -6,7 +6,6 @@ import ( "time" "github.com/reearth/reearth-cms/server/pkg/id" - "github.com/reearth/reearth-cms/server/pkg/key" "github.com/reearth/reearthx/rerror" "github.com/stretchr/testify/assert" ) @@ -28,7 +27,7 @@ func TestModel_Clone(t *testing.T) { schema: sId, name: "n1", description: "d1", - key: key.New("123456"), + key: id.NewKey("123456"), public: false, updatedAt: now, order: 2, @@ -141,14 +140,14 @@ func TestModel_Key(t *testing.T) { tests := []struct { name string model Model - want key.Key + want id.Key }{ { name: "test", model: Model{ - key: key.New("123456"), + key: id.NewKey("123456"), }, - want: key.New("123456"), + want: id.NewKey("123456"), }, } for _, tt := range tests { @@ -299,7 +298,7 @@ func TestModel_SetDescription(t *testing.T) { func TestModel_SetKey(t *testing.T) { type args struct { - key key.Key + key id.Key } tests := []struct { name string @@ -309,40 +308,40 @@ func TestModel_SetKey(t *testing.T) { }{ { name: "pass", - args: args{key: key.New("123456")}, - want: Model{key: key.New("123456")}, + args: args{key: id.NewKey("123456")}, + want: Model{key: id.NewKey("123456")}, wantErr: nil, }, { name: "fail", - args: args{key: key.New("a")}, + args: args{key: id.NewKey("a")}, want: Model{}, wantErr: &rerror.Error{ Label: ErrInvalidKey, Err: fmt.Errorf("%s", "a"), }, }, - { - name: "fail 2", - args: args{key: key.New("_aaaaaaaa")}, - want: Model{}, - wantErr: &rerror.Error{ - Label: ErrInvalidKey, - Err: fmt.Errorf("%s", "_aaaaaaaa"), - }, - }, - { - name: "fail 3", - args: args{key: key.New("-aaaaaaaa")}, - want: Model{}, - wantErr: &rerror.Error{ - Label: ErrInvalidKey, - Err: fmt.Errorf("%s", "-aaaaaaaa"), - }, - }, + //{ + // name: "fail 2", + // args: args{key: id.NewKey("_aaaaaaaa")}, + // want: Model{}, + // wantErr: &rerror.Error{ + // Label: ErrInvalidKey, + // Err: fmt.Errorf("%s", "_aaaaaaaa"), + // }, + //}, + //{ + // name: "fail 3", + // args: args{key: id.NewKey("-aaaaaaaa")}, + // want: Model{}, + // wantErr: &rerror.Error{ + // Label: ErrInvalidKey, + // Err: fmt.Errorf("%s", "-aaaaaaaa"), + // }, + //}, { name: "fails assets", - args: args{key: key.New("assets")}, + args: args{key: id.NewKey("assets")}, want: Model{}, wantErr: &rerror.Error{ Label: ErrInvalidKey, @@ -351,7 +350,7 @@ func TestModel_SetKey(t *testing.T) { }, { name: "fails items", - args: args{key: key.New("items")}, + args: args{key: id.NewKey("items")}, want: Model{}, wantErr: &rerror.Error{ Label: ErrInvalidKey, @@ -360,7 +359,7 @@ func TestModel_SetKey(t *testing.T) { }, { name: "empty", - args: args{key: key.New("")}, + args: args{key: id.NewKey("")}, want: Model{}, wantErr: &rerror.Error{ Label: ErrInvalidKey, diff --git a/server/pkg/schema/corresponding_field.go b/server/pkg/schema/corresponding_field.go index e24d80f2d6..db7617e0f4 100644 --- a/server/pkg/schema/corresponding_field.go +++ b/server/pkg/schema/corresponding_field.go @@ -2,7 +2,6 @@ package schema import ( "github.com/reearth/reearth-cms/server/pkg/id" - "github.com/reearth/reearth-cms/server/pkg/key" "github.com/reearth/reearth-cms/server/pkg/value" ) @@ -20,7 +19,7 @@ func CreateCorrespondingField(sid id.SchemaID, mid id.ModelID, f *Field, inp Cor Required(inp.Required). Name(inp.Title). Description(inp.Description). - Key(key.New(inp.Key)). + Key(id.NewKey(inp.Key)). DefaultValue(nil). Build() if err != nil { diff --git a/server/pkg/schema/corresponding_field_test.go b/server/pkg/schema/corresponding_field_test.go index e9eb5a5c75..ec3c5b0c82 100644 --- a/server/pkg/schema/corresponding_field_test.go +++ b/server/pkg/schema/corresponding_field_test.go @@ -4,7 +4,6 @@ import ( "testing" "github.com/reearth/reearth-cms/server/pkg/id" - "github.com/reearth/reearth-cms/server/pkg/key" "github.com/stretchr/testify/assert" ) @@ -13,7 +12,7 @@ func TestFieldReferenceFromTypeProperty(t *testing.T) { mid1 := id.NewModelID() sid1 := id.NewSchemaID() fid1 := id.NewFieldID() - f1 := NewField(NewReference(mid1, sid1, nil, nil).TypeProperty()).ID(fid1).Key(key.Random()).MustBuild() + f1 := NewField(NewReference(mid1, sid1, nil, nil).TypeProperty()).ID(fid1).Key(id.RandomKey()).MustBuild() got1, ok := FieldReferenceFromTypeProperty(f1.TypeProperty()) want1 := &FieldReference{ modelID: mid1, @@ -26,7 +25,7 @@ func TestFieldReferenceFromTypeProperty(t *testing.T) { // check that it returns false and nil if type is not reference fid2 := id.NewFieldID() - f2 := NewField(NewText(nil).TypeProperty()).ID(fid2).Key(key.Random()).MustBuild() + f2 := NewField(NewText(nil).TypeProperty()).ID(fid2).Key(id.RandomKey()).MustBuild() got2, ok := FieldReferenceFromTypeProperty(f2.TypeProperty()) assert.False(t, ok) assert.Nil(t, got2) diff --git a/server/pkg/schema/field.go b/server/pkg/schema/field.go index 83e573a56d..05e47e0ef3 100644 --- a/server/pkg/schema/field.go +++ b/server/pkg/schema/field.go @@ -4,7 +4,7 @@ import ( "fmt" "time" - "github.com/reearth/reearth-cms/server/pkg/key" + "github.com/reearth/reearth-cms/server/pkg/id" "github.com/reearth/reearth-cms/server/pkg/value" "github.com/reearth/reearthx/i18n" "github.com/reearth/reearthx/rerror" @@ -16,7 +16,7 @@ type Field struct { id FieldID name string description string - key key.Key + key id.Key unique bool multiple bool required bool @@ -74,11 +74,11 @@ func (f *Field) SetDefaultValue(v *value.Multiple) error { return nil } -func (f *Field) Key() key.Key { +func (f *Field) Key() id.Key { return f.key } -func (f *Field) SetKey(key key.Key) error { +func (f *Field) SetKey(key id.Key) error { if !key.IsValid() { return &rerror.Error{ Label: ErrInvalidKey, diff --git a/server/pkg/schema/field_builder.go b/server/pkg/schema/field_builder.go index f8dd7201cc..06fbb0f129 100644 --- a/server/pkg/schema/field_builder.go +++ b/server/pkg/schema/field_builder.go @@ -4,7 +4,7 @@ import ( "fmt" "time" - "github.com/reearth/reearth-cms/server/pkg/key" + "github.com/reearth/reearth-cms/server/pkg/id" "github.com/reearth/reearth-cms/server/pkg/value" "github.com/reearth/reearthx/i18n" "github.com/reearth/reearthx/rerror" @@ -140,13 +140,13 @@ func (b *FieldBuilder) Description(description string) *FieldBuilder { return b } -func (b *FieldBuilder) Key(key key.Key) *FieldBuilder { +func (b *FieldBuilder) Key(key id.Key) *FieldBuilder { b.f.key = key return b } func (b *FieldBuilder) RandomKey() *FieldBuilder { - b.f.key = key.Random() + b.f.key = id.RandomKey() return b } diff --git a/server/pkg/schema/field_builder_test.go b/server/pkg/schema/field_builder_test.go index 05ced59b12..2fbf77d3ce 100644 --- a/server/pkg/schema/field_builder_test.go +++ b/server/pkg/schema/field_builder_test.go @@ -6,7 +6,6 @@ import ( "time" "github.com/reearth/reearth-cms/server/pkg/id" - "github.com/reearth/reearth-cms/server/pkg/key" "github.com/reearth/reearth-cms/server/pkg/value" "github.com/reearth/reearthx/rerror" "github.com/stretchr/testify/assert" @@ -17,12 +16,12 @@ func TestNewField(t *testing.T) { now := time.Now() tp := NewText(nil).TypeProperty() dv := tp.Type().Value("aaa") - id := id.NewFieldID() - k := key.Random() + fId := id.NewFieldID() + k := id.RandomKey() assert.Equal( t, &Field{ - id: id, + id: fId, name: "name", description: "a", key: k, @@ -35,7 +34,7 @@ func TestNewField(t *testing.T) { defaultValue: dv.AsMultiple(), }, NewField(tp). - ID(id). + ID(fId). Name("name"). Description("a"). Key(k). @@ -50,7 +49,7 @@ func TestNewField(t *testing.T) { ) f := NewField(tp). - ID(id). + ID(fId). RandomKey(). Type(tp). MustBuild() diff --git a/server/pkg/schema/field_test.go b/server/pkg/schema/field_test.go index fbbd94feb2..311240df15 100644 --- a/server/pkg/schema/field_test.go +++ b/server/pkg/schema/field_test.go @@ -6,7 +6,6 @@ import ( "time" "github.com/reearth/reearth-cms/server/pkg/id" - "github.com/reearth/reearth-cms/server/pkg/key" "github.com/reearth/reearth-cms/server/pkg/value" "github.com/reearth/reearthx/rerror" "github.com/samber/lo" @@ -70,7 +69,7 @@ func TestField_Clone(t *testing.T) { id: NewFieldID(), name: "a", description: "b", - key: key.Random(), + key: id.RandomKey(), unique: true, multiple: true, required: true, @@ -131,7 +130,7 @@ func TestField_SetOrder(t *testing.T) { func TestField_SetKey(t *testing.T) { f := &Field{} - k := key.Random() + k := id.RandomKey() assert.NoError(t, f.SetKey(k)) assert.Equal(t, &Field{key: k}, f) assert.Equal(t, k, f.Key()) @@ -139,7 +138,7 @@ func TestField_SetKey(t *testing.T) { assert.Equal(t, &rerror.Error{ Label: ErrInvalidKey, Err: fmt.Errorf("%s", ""), - }, f.SetKey(key.New(""))) + }, f.SetKey(id.NewKey(""))) } func TestField_SetTypeProperty(t *testing.T) { diff --git a/server/pkg/schema/list_test.go b/server/pkg/schema/list_test.go index e6dafaa3bc..07b7cfbd9f 100644 --- a/server/pkg/schema/list_test.go +++ b/server/pkg/schema/list_test.go @@ -4,7 +4,6 @@ import ( "testing" "github.com/reearth/reearth-cms/server/pkg/id" - "github.com/reearth/reearth-cms/server/pkg/key" "github.com/stretchr/testify/assert" ) @@ -44,8 +43,8 @@ func TestList_Schema(t *testing.T) { func TestList_Fields(t *testing.T) { id1 := NewID() id2 := NewID() - f1 := NewField(NewText(nil).TypeProperty()).NewID().Key(key.Random()).MustBuild() - f2 := NewField(NewText(nil).TypeProperty()).NewID().Key(key.Random()).MustBuild() + f1 := NewField(NewText(nil).TypeProperty()).NewID().Key(id.RandomKey()).MustBuild() + f2 := NewField(NewText(nil).TypeProperty()).NewID().Key(id.RandomKey()).MustBuild() list := List{ &Schema{id: id2, fields: FieldList{f2}}, @@ -126,8 +125,8 @@ func TestFieldList_Ordered(t *testing.T) { } func TestFieldList_Find(t *testing.T) { - f := NewField(NewText(nil).TypeProperty()).NewID().Key(key.Random()).MustBuild() - f2 := NewField(NewText(nil).TypeProperty()).NewID().Key(key.Random()).MustBuild() + f := NewField(NewText(nil).TypeProperty()).NewID().Key(id.RandomKey()).MustBuild() + f2 := NewField(NewText(nil).TypeProperty()).NewID().Key(id.RandomKey()).MustBuild() assert.Equal(t, f, FieldList{f, f2}.Find(f.ID())) assert.Equal(t, f2, FieldList{f, f2}.Find(f2.ID())) assert.Nil(t, FieldList{f, f2}.Find(NewFieldID())) diff --git a/server/pkg/schema/package_test.go b/server/pkg/schema/package_test.go index 87ac902ad9..a4ddd74cc2 100644 --- a/server/pkg/schema/package_test.go +++ b/server/pkg/schema/package_test.go @@ -4,7 +4,6 @@ import ( "testing" "github.com/reearth/reearth-cms/server/pkg/id" - "github.com/reearth/reearth-cms/server/pkg/key" "github.com/stretchr/testify/assert" ) @@ -13,9 +12,9 @@ func TestPackage_New(t *testing.T) { msID := id.NewSchemaID() gsID := id.NewSchemaID() gID := id.NewGroupID() - f1 := NewField(NewText(nil).TypeProperty()).NewID().Key(key.Random()).MustBuild() - f2 := NewField(NewText(nil).TypeProperty()).NewID().Key(key.Random()).MustBuild() - f3 := NewField(NewText(nil).TypeProperty()).NewID().Key(key.Random()).MustBuild() + f1 := NewField(NewText(nil).TypeProperty()).NewID().Key(id.RandomKey()).MustBuild() + f2 := NewField(NewText(nil).TypeProperty()).NewID().Key(id.RandomKey()).MustBuild() + f3 := NewField(NewText(nil).TypeProperty()).NewID().Key(id.RandomKey()).MustBuild() s := &Schema{id: sID, fields: FieldList{f1}} meta := &Schema{id: msID, fields: FieldList{f2}} groupSchemas := make(map[id.GroupID]*Schema) @@ -35,9 +34,9 @@ func TestPackage_Schema(t *testing.T) { msID := id.NewSchemaID() gsID := id.NewSchemaID() gID := id.NewGroupID() - f1 := NewField(NewText(nil).TypeProperty()).NewID().Key(key.Random()).MustBuild() - f2 := NewField(NewText(nil).TypeProperty()).NewID().Key(key.Random()).MustBuild() - f3 := NewField(NewText(nil).TypeProperty()).NewID().Key(key.Random()).MustBuild() + f1 := NewField(NewText(nil).TypeProperty()).NewID().Key(id.RandomKey()).MustBuild() + f2 := NewField(NewText(nil).TypeProperty()).NewID().Key(id.RandomKey()).MustBuild() + f3 := NewField(NewText(nil).TypeProperty()).NewID().Key(id.RandomKey()).MustBuild() s := &Schema{id: sID, fields: FieldList{f1}} meta := &Schema{id: msID, fields: FieldList{f2}} groupSchemas := make(map[id.GroupID]*Schema) @@ -53,9 +52,9 @@ func TestPackage_MetaSchema(t *testing.T) { msID := id.NewSchemaID() gsID := id.NewSchemaID() gID := id.NewGroupID() - f1 := NewField(NewText(nil).TypeProperty()).NewID().Key(key.Random()).MustBuild() - f2 := NewField(NewText(nil).TypeProperty()).NewID().Key(key.Random()).MustBuild() - f3 := NewField(NewText(nil).TypeProperty()).NewID().Key(key.Random()).MustBuild() + f1 := NewField(NewText(nil).TypeProperty()).NewID().Key(id.RandomKey()).MustBuild() + f2 := NewField(NewText(nil).TypeProperty()).NewID().Key(id.RandomKey()).MustBuild() + f3 := NewField(NewText(nil).TypeProperty()).NewID().Key(id.RandomKey()).MustBuild() s := &Schema{id: sID, fields: FieldList{f1}} meta := &Schema{id: msID, fields: FieldList{f2}} groupSchemas := make(map[id.GroupID]*Schema) @@ -71,9 +70,9 @@ func TestPackage_GroupSchemas(t *testing.T) { msID := id.NewSchemaID() gsID := id.NewSchemaID() gID := id.NewGroupID() - f1 := NewField(NewText(nil).TypeProperty()).NewID().Key(key.Random()).MustBuild() - f2 := NewField(NewText(nil).TypeProperty()).NewID().Key(key.Random()).MustBuild() - f3 := NewField(NewText(nil).TypeProperty()).NewID().Key(key.Random()).MustBuild() + f1 := NewField(NewText(nil).TypeProperty()).NewID().Key(id.RandomKey()).MustBuild() + f2 := NewField(NewText(nil).TypeProperty()).NewID().Key(id.RandomKey()).MustBuild() + f3 := NewField(NewText(nil).TypeProperty()).NewID().Key(id.RandomKey()).MustBuild() s := &Schema{id: sID, fields: FieldList{f1}} meta := &Schema{id: msID, fields: FieldList{f2}} groupSchemas := make(map[id.GroupID]*Schema) @@ -89,9 +88,9 @@ func TestPackage_GroupSchema(t *testing.T) { msID := id.NewSchemaID() gsID := id.NewSchemaID() gID := id.NewGroupID() - f1 := NewField(NewText(nil).TypeProperty()).NewID().Key(key.Random()).MustBuild() - f2 := NewField(NewText(nil).TypeProperty()).NewID().Key(key.Random()).MustBuild() - f3 := NewField(NewText(nil).TypeProperty()).NewID().Key(key.Random()).MustBuild() + f1 := NewField(NewText(nil).TypeProperty()).NewID().Key(id.RandomKey()).MustBuild() + f2 := NewField(NewText(nil).TypeProperty()).NewID().Key(id.RandomKey()).MustBuild() + f3 := NewField(NewText(nil).TypeProperty()).NewID().Key(id.RandomKey()).MustBuild() s := &Schema{id: sID, fields: FieldList{f1}} meta := &Schema{id: msID, fields: FieldList{f2}} groupSchemas := make(map[id.GroupID]*Schema) @@ -108,9 +107,9 @@ func TestPackage_Field(t *testing.T) { msID := id.NewSchemaID() gsID := id.NewSchemaID() gID := id.NewGroupID() - f1 := NewField(NewText(nil).TypeProperty()).NewID().Key(key.Random()).MustBuild() - f2 := NewField(NewText(nil).TypeProperty()).NewID().Key(key.Random()).MustBuild() - f3 := NewField(NewText(nil).TypeProperty()).NewID().Key(key.Random()).MustBuild() + f1 := NewField(NewText(nil).TypeProperty()).NewID().Key(id.RandomKey()).MustBuild() + f2 := NewField(NewText(nil).TypeProperty()).NewID().Key(id.RandomKey()).MustBuild() + f3 := NewField(NewText(nil).TypeProperty()).NewID().Key(id.RandomKey()).MustBuild() s := &Schema{id: sID, fields: FieldList{f1}} meta := &Schema{id: msID, fields: FieldList{f2}} groupSchemas := make(map[id.GroupID]*Schema) diff --git a/server/pkg/schema/schema.go b/server/pkg/schema/schema.go index 53acbd1adc..caf8915348 100644 --- a/server/pkg/schema/schema.go +++ b/server/pkg/schema/schema.go @@ -4,7 +4,6 @@ import ( "errors" "github.com/reearth/reearth-cms/server/pkg/id" - "github.com/reearth/reearth-cms/server/pkg/key" "github.com/reearth/reearth-cms/server/pkg/value" "github.com/reearth/reearthx/account/accountdomain" "github.com/samber/lo" @@ -87,7 +86,7 @@ func (s *Schema) Field(fId FieldID) *Field { return f } -func (s *Schema) FieldByIDOrKey(fId *FieldID, key *key.Key) *Field { +func (s *Schema) FieldByIDOrKey(fId *FieldID, key *id.Key) *Field { if s == nil || s.fields == nil { return nil } diff --git a/server/pkg/schema/schema_test.go b/server/pkg/schema/schema_test.go index 3b96dcc85a..a3c6275155 100644 --- a/server/pkg/schema/schema_test.go +++ b/server/pkg/schema/schema_test.go @@ -4,7 +4,6 @@ import ( "testing" "github.com/reearth/reearth-cms/server/pkg/id" - "github.com/reearth/reearth-cms/server/pkg/key" "github.com/reearth/reearth-cms/server/pkg/value" "github.com/reearth/reearthx/account/accountdomain" "github.com/stretchr/testify/assert" @@ -203,8 +202,8 @@ func TestSchema_Field(t *testing.T) { func TestSchema_FieldByIDOrKey(t *testing.T) { f1 := &Field{id: NewFieldID(), name: "f1"} f2 := &Field{id: NewFieldID(), name: "f2"} - f3 := &Field{id: NewFieldID(), name: "f3", key: key.New("KEY")} - f4 := &Field{id: NewFieldID(), name: "f4", key: key.New("id")} + f3 := &Field{id: NewFieldID(), name: "f3", key: id.NewKey("KEY")} + f4 := &Field{id: NewFieldID(), name: "f4", key: id.NewKey("id")} s := &Schema{fields: []*Field{f1, f2, f3, f4}} assert.Equal(t, f1, s.FieldByIDOrKey(f1.ID().Ref(), nil)) @@ -214,9 +213,9 @@ func TestSchema_FieldByIDOrKey(t *testing.T) { assert.Equal(t, f3, s.FieldByIDOrKey(nil, f3.Key().Ref())) assert.Equal(t, f1, s.FieldByIDOrKey(f1.ID().Ref(), f3.Key().Ref())) assert.Nil(t, s.FieldByIDOrKey(id.NewFieldID().Ref(), nil)) - assert.Nil(t, s.FieldByIDOrKey(nil, key.New("").Ref())) - assert.Nil(t, s.FieldByIDOrKey(nil, key.New("x").Ref())) - assert.Nil(t, s.FieldByIDOrKey(nil, key.New("id").Ref())) + assert.Nil(t, s.FieldByIDOrKey(nil, id.NewKey("").Ref())) + assert.Nil(t, s.FieldByIDOrKey(nil, id.NewKey("x").Ref())) + assert.Nil(t, s.FieldByIDOrKey(nil, id.NewKey("id").Ref())) } func TestSchema_Fields(t *testing.T) { @@ -403,7 +402,7 @@ func TestSchema_TitleField(t *testing.T) { } func TestSchema_SetTitleField(t *testing.T) { - sf := NewField(NewBool().TypeProperty()).NewID().Key(key.Random()).MustBuild() + sf := NewField(NewBool().TypeProperty()).NewID().Key(id.RandomKey()).MustBuild() f := []*Field{sf} s := New().NewID().Project(id.NewProjectID()).Workspace(accountdomain.NewWorkspaceID()).Fields(f).MustBuild() @@ -453,13 +452,13 @@ func TestSchema_HasFieldByKey(t *testing.T) { }, { name: "add on not empty array", - s: &Schema{fields: []*Field{{id: fid1, name: "f1", key: key.New("K123123")}}}, + s: &Schema{fields: []*Field{{id: fid1, name: "f1", key: id.NewKey("K123123")}}}, fKey: "K123123", want: true, }, { name: "add duplicated field", - s: &Schema{fields: []*Field{{id: fid1, name: "f1", key: key.New("K123123")}, {id: fid2, name: "f2", key: key.New("K111222")}, {id: fid3, name: "f3", key: key.New("K123111")}}}, + s: &Schema{fields: []*Field{{id: fid1, name: "f1", key: id.NewKey("K123123")}, {id: fid2, name: "f2", key: id.NewKey("K111222")}, {id: fid3, name: "f3", key: id.NewKey("K123111")}}}, fKey: "K123123", want: true, },