Skip to content

Commit

Permalink
refactoring id project and workspace
Browse files Browse the repository at this point in the history
  • Loading branch information
hexaforce committed Feb 17, 2025
1 parent 49554df commit c3e9319
Show file tree
Hide file tree
Showing 15 changed files with 61 additions and 43 deletions.
2 changes: 1 addition & 1 deletion server/internal/infrastructure/memory/project.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ func (r *Project) FindDeletedByWorkspace(ctx context.Context, id accountdomain.W
return result, nil
}

func (r *Project) FindIDsByWorkspace(ctx context.Context, id accountdomain.WorkspaceID) (res []project.ID, _ error) {
func (r *Project) FindIDsByWorkspace(ctx context.Context, id accountdomain.WorkspaceID) (res []id.ProjectID, _ error) {
r.lock.Lock()
defer r.lock.Unlock()

Expand Down
6 changes: 4 additions & 2 deletions server/pkg/asset/asset.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package asset
import (
"errors"
"time"

"github.com/reearth/reearthx/account/accountdomain"
)

var (
Expand All @@ -14,7 +16,7 @@ var (
type Asset struct {
id ID
createdAt time.Time
workspace WorkspaceID
workspace accountdomain.WorkspaceID
name string // file name
size int64 // file size
url string
Expand All @@ -26,7 +28,7 @@ func (a *Asset) ID() ID {
return a.id
}

func (a *Asset) Workspace() WorkspaceID {
func (a *Asset) Workspace() accountdomain.WorkspaceID {
return a.workspace
}

Expand Down
4 changes: 2 additions & 2 deletions server/pkg/asset/asset_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ func TestAsset(t *testing.T) {
Expected struct {
ID ID
CreatedAt time.Time
Workspace WorkspaceID
Workspace accountdomain.WorkspaceID
Name string
Size int64
URL string
Expand All @@ -31,7 +31,7 @@ func TestAsset(t *testing.T) {
Expected: struct {
ID ID
CreatedAt time.Time
Workspace WorkspaceID
Workspace accountdomain.WorkspaceID
Name string
Size int64
URL string
Expand Down
4 changes: 3 additions & 1 deletion server/pkg/asset/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package asset

import (
"time"

"github.com/reearth/reearthx/account/accountdomain"
)

type Builder struct {
Expand Down Expand Up @@ -49,7 +51,7 @@ func (b *Builder) NewID() *Builder {
return b
}

func (b *Builder) Workspace(workspace WorkspaceID) *Builder {
func (b *Builder) Workspace(workspace accountdomain.WorkspaceID) *Builder {
b.a.workspace = workspace
return b
}
Expand Down
8 changes: 4 additions & 4 deletions server/pkg/asset/builder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ func TestBuilder_Build(t *testing.T) {
id ID
name string
createdAt time.Time
workspace WorkspaceID
workspace accountdomain.WorkspaceID
size int64
url string
contentType string
Expand Down Expand Up @@ -79,7 +79,7 @@ func TestBuilder_Build(t *testing.T) {
args: args{
id: NewID(),
createdAt: d,
workspace: WorkspaceID{},
workspace: accountdomain.WorkspaceID{},
size: 10,
url: "tt://xxx.zz",
contentType: "bbb",
Expand Down Expand Up @@ -133,7 +133,7 @@ func TestBuilder_MustBuild(t *testing.T) {
id ID
name string
createdAt time.Time
workspace WorkspaceID
workspace accountdomain.WorkspaceID
size int64
url string
contentType string
Expand Down Expand Up @@ -195,7 +195,7 @@ func TestBuilder_MustBuild(t *testing.T) {
args: args{
createdAt: d,
id: NewID(),
workspace: WorkspaceID{},
workspace: accountdomain.WorkspaceID{},
size: 10,
url: "tt://xxx.zz",
contentType: "bbb",
Expand Down
3 changes: 2 additions & 1 deletion server/pkg/asset/id.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ import (
)

type ID = id.AssetID
type WorkspaceID = accountdomain.WorkspaceID

// type WorkspaceID = accountdomain.WorkspaceID

var NewID = id.NewAssetID
var NewWorkspaceID = accountdomain.NewWorkspaceID
Expand Down
6 changes: 4 additions & 2 deletions server/pkg/project/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ import (
"net/url"
"time"

"github.com/reearth/reearth/server/pkg/id"
"github.com/reearth/reearth/server/pkg/visualizer"
"github.com/reearth/reearthx/account/accountdomain"
)

type Builder struct {
Expand Down Expand Up @@ -36,7 +38,7 @@ func (b *Builder) MustBuild() *Project {
return r
}

func (b *Builder) ID(id ID) *Builder {
func (b *Builder) ID(id id.ProjectID) *Builder {
b.p.id = id
return b
}
Expand Down Expand Up @@ -127,7 +129,7 @@ func (b *Builder) CoreSupport(coreSupport bool) *Builder {
return b
}

func (b *Builder) Workspace(workspace WorkspaceID) *Builder {
func (b *Builder) Workspace(workspace accountdomain.WorkspaceID) *Builder {
b.p.workspace = workspace
return b
}
Expand Down
9 changes: 5 additions & 4 deletions server/pkg/project/builder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"testing"
"time"

"github.com/reearth/reearth/server/pkg/id"
"github.com/reearth/reearth/server/pkg/visualizer"
"github.com/reearth/reearthx/account/accountdomain"
"github.com/stretchr/testify/assert"
Expand Down Expand Up @@ -170,13 +171,13 @@ func TestBuilder_Build(t *testing.T) {
alias, publicTitle string
publicDescription string
publicImage string
id ID
id id.ProjectID
isArchived bool
updatedAt time.Time
publishedAt time.Time
imageURL *url.URL
publicNoIndex bool
workspace WorkspaceID
workspace accountdomain.WorkspaceID
visualizer visualizer.Visualizer
publishmentStatus PublishmentStatus
}
Expand Down Expand Up @@ -291,13 +292,13 @@ func TestBuilder_MustBuild(t *testing.T) {
alias, publicTitle string
publicDescription string
publicImage string
id ID
id id.ProjectID
isArchived bool
updatedAt time.Time
publishedAt time.Time
imageURL *url.URL
publicNoIndex bool
workspace WorkspaceID
workspace accountdomain.WorkspaceID
visualizer visualizer.Visualizer
publishmentStatus PublishmentStatus
trackingId string
Expand Down
8 changes: 4 additions & 4 deletions server/pkg/project/id.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import (
"github.com/reearth/reearthx/account/accountdomain"
)

type ID = id.ProjectID
type WorkspaceID = accountdomain.WorkspaceID
// type ID = id.ProjectID
// type WorkspaceID = accountdomain.WorkspaceID
type SceneID = id.SceneID

var NewID = id.NewProjectID
Expand All @@ -23,8 +23,8 @@ var WorkspaceIDFromRef = accountdomain.WorkspaceIDFromRef

var ErrInvalidID = id.ErrInvalidID

func MockNewID(pid ID) func() {
NewID = func() ID { return pid }
func MockNewID(pid id.ProjectID) func() {
NewID = func() id.ProjectID { return pid }
return func() {
NewID = id.NewProjectID
}
Expand Down
12 changes: 7 additions & 5 deletions server/pkg/project/project.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@ import (
"github.com/reearth/reearth/server/pkg/i18n/message"
"github.com/reearth/reearth/server/pkg/i18n/message/entitymsg"
"github.com/reearth/reearth/server/pkg/i18n/message/errmsg"
"github.com/reearth/reearth/server/pkg/id"
"github.com/reearth/reearth/server/pkg/verror"
"github.com/reearth/reearth/server/pkg/visualizer"
"github.com/reearth/reearthx/account/accountdomain"
"golang.org/x/text/language"
)

Expand All @@ -28,7 +30,7 @@ var (
)

type Project struct {
id ID
id id.ProjectID
isArchived bool
isBasicAuthActive bool
basicAuthUsername string
Expand All @@ -43,7 +45,7 @@ type Project struct {
publicDescription string
publicImage string
publicNoIndex bool
workspace WorkspaceID
workspace accountdomain.WorkspaceID
visualizer visualizer.Visualizer
publishmentStatus PublishmentStatus
coreSupport bool
Expand All @@ -54,7 +56,7 @@ type Project struct {
isDeleted bool
}

func (p *Project) ID() ID {
func (p *Project) ID() id.ProjectID {
return p.id
}

Expand Down Expand Up @@ -139,7 +141,7 @@ func (p *Project) PublishmentStatus() PublishmentStatus {
return p.publishmentStatus
}

func (p *Project) Workspace() WorkspaceID {
func (p *Project) Workspace() accountdomain.WorkspaceID {
return p.workspace
}

Expand Down Expand Up @@ -234,7 +236,7 @@ func (p *Project) UpdatePublicNoIndex(publicNoIndex bool) {
p.publicNoIndex = publicNoIndex
}

func (p *Project) UpdateWorkspace(workspace WorkspaceID) {
func (p *Project) UpdateWorkspace(workspace accountdomain.WorkspaceID) {
p.workspace = workspace
}

Expand Down
7 changes: 5 additions & 2 deletions server/pkg/scene/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ package scene

import (
"time"

"github.com/reearth/reearth/server/pkg/id"
"github.com/reearth/reearthx/account/accountdomain"
)

type Builder struct {
Expand Down Expand Up @@ -52,12 +55,12 @@ func (b *Builder) NewID() *Builder {
return b
}

func (b *Builder) Project(prj ProjectID) *Builder {
func (b *Builder) Project(prj id.ProjectID) *Builder {
b.scene.project = prj
return b
}

func (b *Builder) Workspace(workspace WorkspaceID) *Builder {
func (b *Builder) Workspace(workspace accountdomain.WorkspaceID) *Builder {
b.scene.workspace = workspace
return b
}
Expand Down
13 changes: 7 additions & 6 deletions server/pkg/scene/builder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"testing"
"time"

"github.com/reearth/reearth/server/pkg/id"
"github.com/reearth/reearthx/account/accountdomain"
"github.com/stretchr/testify/assert"
)
Expand Down Expand Up @@ -69,8 +70,8 @@ func TestBuilder_Build(t *testing.T) {

type args struct {
ID ID
Project ProjectID
Workspace WorkspaceID
Project id.ProjectID
Workspace accountdomain.WorkspaceID
RootLayer LayerID
Widgets *Widgets
Plugins *Plugins
Expand Down Expand Up @@ -103,7 +104,7 @@ func TestBuilder_Build(t *testing.T) {
Args: args{
ID: sid,
Project: pid,
Workspace: WorkspaceID{},
Workspace: accountdomain.WorkspaceID{},
RootLayer: lid,
Widgets: ws,
Plugins: ps,
Expand Down Expand Up @@ -191,8 +192,8 @@ func TestBuilder_MustBuild(t *testing.T) {

type args struct {
ID ID
Project ProjectID
Workspace WorkspaceID
Project id.ProjectID
Workspace accountdomain.WorkspaceID
RootLayer LayerID
Widgets *Widgets
WidgetAlignSystem *WidgetAlignSystem
Expand Down Expand Up @@ -227,7 +228,7 @@ func TestBuilder_MustBuild(t *testing.T) {
Args: args{
ID: sid,
Project: pid,
Workspace: WorkspaceID{},
Workspace: accountdomain.WorkspaceID{},
RootLayer: lid,
Widgets: ws,
WidgetAlignSystem: was,
Expand Down
5 changes: 3 additions & 2 deletions server/pkg/scene/id.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@ type LayerID = id.LayerID
type PropertyID = id.PropertyID
type PluginID = id.PluginID
type PluginExtensionID = id.PluginExtensionID
type ProjectID = id.ProjectID
type WorkspaceID = accountdomain.WorkspaceID

// type ProjectID = id.ProjectID
// type WorkspaceID = accountdomain.WorkspaceID
type StyleID = id.StyleID

type IDList = id.SceneIDList
Expand Down
4 changes: 3 additions & 1 deletion server/pkg/scene/list.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package scene

import "github.com/reearth/reearthx/account/accountdomain"

type List []*Scene

func (l List) IDs() []ID {
Expand Down Expand Up @@ -32,7 +34,7 @@ func (l List) FilterByID(ids ...ID) List {
return res
}

func (l List) FilterByWorkspace(workspaces ...WorkspaceID) List {
func (l List) FilterByWorkspace(workspaces ...accountdomain.WorkspaceID) List {
if l == nil {
return nil
}
Expand Down
Loading

0 comments on commit c3e9319

Please sign in to comment.