Skip to content

Commit 86fac8e

Browse files
authored
Merge branch 'main' into refactor/dataAttribution
2 parents ec382a9 + e1f2063 commit 86fac8e

25 files changed

Lines changed: 12967 additions & 8359 deletions

File tree

.github/CODEOWNERS

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
* @rot1024
22

3-
/server/ @pyshx
3+
/server/ @pyshx @soneda-yuya
44

55

66
/web/ @airslice @mkumbobeaty

server/internal/adapter/gql/gqlmodel/scalar_id.go

Lines changed: 28 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package gqlmodel
22

33
import (
4-
"errors"
4+
"fmt"
55
"io"
66
"strconv"
77

@@ -22,7 +22,7 @@ func UnmarshalPropertyFieldID(v interface{}) (id.PropertyFieldID, error) {
2222
if tmpStr, ok := v.(string); ok {
2323
return id.PropertyFieldID(tmpStr), nil
2424
}
25-
return id.PropertyFieldID(""), errors.New("invalid ID")
25+
return id.PropertyFieldID(""), fmt.Errorf("invalid propertyField ID: %v", v)
2626
}
2727

2828
func MarshalDatasetFieldID(t id.DatasetFieldID) graphql.Marshaler {
@@ -33,9 +33,13 @@ func MarshalDatasetFieldID(t id.DatasetFieldID) graphql.Marshaler {
3333

3434
func UnmarshalDatasetFieldID(v interface{}) (id.DatasetFieldID, error) {
3535
if tmpStr, ok := v.(string); ok {
36-
return id.DatasetFieldIDFrom(tmpStr)
36+
res, err := id.DatasetFieldIDFrom(tmpStr)
37+
if err != nil {
38+
return res, fmt.Errorf("invalid datasetField ID: %s", tmpStr)
39+
}
40+
return res, nil
3741
}
38-
return id.NewDatasetFieldID(), errors.New("invalid ID")
42+
return id.NewDatasetFieldID(), fmt.Errorf("invalid datasetField ID: %v", v)
3943
}
4044

4145
func MarshalPluginID(t id.PluginID) graphql.Marshaler {
@@ -46,9 +50,13 @@ func MarshalPluginID(t id.PluginID) graphql.Marshaler {
4650

4751
func UnmarshalPluginID(v interface{}) (id.PluginID, error) {
4852
if tmpStr, ok := v.(string); ok {
49-
return id.PluginIDFrom(tmpStr)
53+
res, err := id.PluginIDFrom(tmpStr)
54+
if err != nil {
55+
return res, fmt.Errorf("invalid plugin ID: %s", tmpStr)
56+
}
57+
return res, nil
5058
}
51-
return id.PluginID{}, errors.New("invalid ID")
59+
return id.PluginID{}, fmt.Errorf("invalid plugin ID: %v", v)
5260
}
5361

5462
func MarshalPluginExtensionID(t id.PluginExtensionID) graphql.Marshaler {
@@ -61,7 +69,7 @@ func UnmarshalPluginExtensionID(v interface{}) (id.PluginExtensionID, error) {
6169
if tmpStr, ok := v.(string); ok {
6270
return id.PluginExtensionID(tmpStr), nil
6371
}
64-
return id.PluginExtensionID(""), errors.New("invalid ID")
72+
return id.PluginExtensionID(""), fmt.Errorf("invalid pluginExtension ID: %v", v)
6573
}
6674

6775
func MarshalPropertySchemaID(t id.PropertySchemaID) graphql.Marshaler {
@@ -72,9 +80,13 @@ func MarshalPropertySchemaID(t id.PropertySchemaID) graphql.Marshaler {
7280

7381
func UnmarshalPropertySchemaID(v interface{}) (id.PropertySchemaID, error) {
7482
if tmpStr, ok := v.(string); ok {
75-
return id.PropertySchemaIDFrom(tmpStr)
83+
res, err := id.PropertySchemaIDFrom(tmpStr)
84+
if err != nil {
85+
return res, fmt.Errorf("invalid propertySchema ID: %s", tmpStr)
86+
}
87+
return res, nil
7688
}
77-
return id.PropertySchemaID{}, errors.New("invalid ID")
89+
return id.PropertySchemaID{}, fmt.Errorf("invalid propertySchema ID: %v", v)
7890
}
7991

8092
func MarshalPropertySchemaGroupID(t id.PropertySchemaGroupID) graphql.Marshaler {
@@ -87,7 +99,7 @@ func UnmarshalPropertySchemaGroupID(v interface{}) (id.PropertySchemaGroupID, er
8799
if tmpStr, ok := v.(string); ok {
88100
return id.PropertySchemaGroupID(tmpStr), nil
89101
}
90-
return id.PropertySchemaGroupID(""), errors.New("invalid ID")
102+
return id.PropertySchemaGroupID(""), fmt.Errorf("invalid propertySchemaGroup ID: %v", v)
91103
}
92104

93105
func IDFrom[T idx.Type](i idx.ID[T]) ID {
@@ -134,7 +146,12 @@ func IDFromPropertySchemaIDRef(i *id.PropertySchemaID) *ID {
134146
}
135147

136148
func ToID[A idx.Type](a ID) (idx.ID[A], error) {
137-
return idx.From[A](string(a))
149+
res, err := idx.From[A](string(a))
150+
if err != nil {
151+
var t A
152+
return res, fmt.Errorf("invalid %s ID: %s", t.Type(), string(a))
153+
}
154+
return res, nil
138155
}
139156

140157
func ToIDs[A idx.Type](a []ID) (*[]idx.ID[A], error) {

server/internal/adapter/gql/loader_scene.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,13 @@ package gql
22

33
import (
44
"context"
5+
"errors"
56

67
"github.com/reearth/reearth/server/internal/adapter/gql/gqldataloader"
78
"github.com/reearth/reearth/server/internal/adapter/gql/gqlmodel"
89
"github.com/reearth/reearth/server/internal/usecase/interfaces"
910
"github.com/reearth/reearth/server/pkg/id"
11+
"github.com/reearth/reearthx/rerror"
1012
"github.com/reearth/reearthx/util"
1113
)
1214

@@ -44,6 +46,9 @@ func (c *SceneLoader) FindByProject(ctx context.Context, projectID gqlmodel.ID)
4446

4547
res, err := c.usecase.FindByProject(ctx, pid, getOperator(ctx))
4648
if err != nil {
49+
if errors.Is(err, rerror.ErrNotFound) {
50+
return nil, nil
51+
}
4752
return nil, err
4853
}
4954

server/internal/infrastructure/memory/project.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,11 @@ func (r *Project) FindByWorkspace(ctx context.Context, id accountdomain.Workspac
4242
}
4343

4444
result := []*project.Project{}
45+
var totalCount int64
4546
for _, d := range r.data {
46-
if d.Workspace() == id {
47+
if d.Workspace() == id && !d.CoreSupport() {
4748
result = append(result, d)
49+
totalCount++
4850
}
4951
}
5052

@@ -57,11 +59,11 @@ func (r *Project) FindByWorkspace(ctx context.Context, id accountdomain.Workspac
5759
}
5860

5961
return result, usecasex.NewPageInfo(
60-
int64(len(r.data)),
62+
totalCount,
6163
startCursor,
6264
endCursor,
63-
true,
64-
true,
65+
false,
66+
false,
6567
), nil
6668
}
6769

server/internal/infrastructure/mongo/asset.go

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ import (
2323
)
2424

2525
var (
26-
assetIndexes = []string{"team"}
26+
assetIndexes = []string{"team", "workspace"}
2727
assetUniqueIndexes = []string{"id"}
2828
)
2929

@@ -180,9 +180,10 @@ func (r *Asset) FindByWorkspace(ctx context.Context, id accountdomain.WorkspaceI
180180
return nil, usecasex.EmptyPageInfo(), nil
181181
}
182182

183-
absoluteFilter := bson.M{
184-
"team": id.String(),
185-
}
183+
absoluteFilter := bson.M{"$or": []bson.M{
184+
{"workspace": id.String()},
185+
{"team": id.String()},
186+
}}
186187

187188
if f.Keyword != nil {
188189
keywordRegex := primitive.Regex{
@@ -257,7 +258,10 @@ func (r *Asset) TotalSizeByWorkspace(ctx context.Context, wid accountdomain.Work
257258
}
258259

259260
c, err := r.client.Client().Aggregate(ctx, []bson.M{
260-
{"$match": bson.M{"team": wid.String()}},
261+
{"$match": bson.M{"$or": []bson.M{
262+
{"workspace": wid.String()},
263+
{"team": wid.String()},
264+
}}},
261265
{"$group": bson.M{"_id": nil, "size": bson.M{"$sum": "$size"}}},
262266
})
263267
if err != nil {

server/internal/infrastructure/mongo/container.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,13 @@ func applyWorkspaceFilter(filter interface{}, ids user.WorkspaceIDList) interfac
142142
if ids == nil {
143143
return filter
144144
}
145-
return mongox.And(filter, "team", bson.M{"$in": ids.Strings()})
145+
return mongox.And(filter, "",
146+
bson.M{"$or": []bson.M{
147+
{"workspace": bson.M{"$in": ids.Strings()}},
148+
{"team": bson.M{"$in": ids.Strings()}},
149+
},
150+
},
151+
)
146152
}
147153

148154
func applySceneFilter(filter interface{}, ids scene.IDList) interface{} {

server/internal/infrastructure/mongo/mongodoc/asset.go

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ import (
1212
type AssetDocument struct {
1313
ID string
1414
CreatedAt time.Time
15-
Team string // DON'T CHANGE NAME'
15+
Team string `bson:"team,omitempty"` // legacy field name
16+
Workspace string `bson:"workspace,omitempty"` // new field name
1617
Name string
1718
Size int64
1819
URL string
@@ -32,7 +33,7 @@ func NewAsset(asset *asset.Asset) (*AssetDocument, string) {
3233
return &AssetDocument{
3334
ID: aid,
3435
CreatedAt: asset.CreatedAt(),
35-
Team: asset.Workspace().String(),
36+
Workspace: asset.Workspace().String(),
3637
Name: asset.Name(),
3738
Size: asset.Size(),
3839
URL: asset.URL(),
@@ -45,7 +46,11 @@ func (d *AssetDocument) Model() (*asset.Asset, error) {
4546
if err != nil {
4647
return nil, err
4748
}
48-
tid, err := accountdomain.WorkspaceIDFrom(d.Team)
49+
workspace := d.Workspace
50+
if workspace == "" {
51+
workspace = d.Team
52+
}
53+
tid, err := accountdomain.WorkspaceIDFrom(workspace)
4954
if err != nil {
5055
return nil, err
5156
}

server/internal/infrastructure/mongo/mongodoc/project.go

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ type ProjectDocument struct {
2828
PublicImage string
2929
PublicNoIndex bool
3030
Team string // DON'T CHANGE NAME'
31+
Workspace string `bson:"workspace,omitempty"`
3132
Visualizer string
3233
PublishmentStatus string
3334
CoreSupport bool
@@ -52,6 +53,8 @@ func NewProject(project *project.Project) (*ProjectDocument, string) {
5253
imageURL = u.String()
5354
}
5455

56+
workspace := project.Workspace().String()
57+
5558
return &ProjectDocument{
5659
ID: pid,
5760
Archived: project.IsArchived(),
@@ -68,7 +71,7 @@ func NewProject(project *project.Project) (*ProjectDocument, string) {
6871
PublicDescription: project.PublicDescription(),
6972
PublicImage: project.PublicImage(),
7073
PublicNoIndex: project.PublicNoIndex(),
71-
Team: project.Workspace().String(),
74+
Workspace: workspace,
7275
Visualizer: string(project.Visualizer()),
7376
PublishmentStatus: string(project.PublishmentStatus()),
7477
CoreSupport: project.CoreSupport(),
@@ -83,7 +86,11 @@ func (d *ProjectDocument) Model() (*project.Project, error) {
8386
if err != nil {
8487
return nil, err
8588
}
86-
tid, err := accountdomain.WorkspaceIDFrom(d.Team)
89+
workspace := d.Workspace
90+
if workspace == "" {
91+
workspace = d.Team
92+
}
93+
tid, err := accountdomain.WorkspaceIDFrom(workspace)
8794
if err != nil {
8895
return nil, err
8996
}

0 commit comments

Comments
 (0)