diff --git a/internal/app/main.go b/internal/app/main.go index 0f4cf6cd..bdce1744 100644 --- a/internal/app/main.go +++ b/internal/app/main.go @@ -86,7 +86,7 @@ func (w *WebServer) Run() { if w.appServer.Debug { debugLog += " with debug mode" } - log.Infof("server started%s at %s\n", debugLog, w.address) + log.Infof("server started%s at http://%s\n", debugLog, w.address) go func() { err := w.appServer.Start(w.address) diff --git a/internal/infrastructure/mongo/asset.go b/internal/infrastructure/mongo/asset.go index cb78cc28..4097a23c 100644 --- a/internal/infrastructure/mongo/asset.go +++ b/internal/infrastructure/mongo/asset.go @@ -60,7 +60,7 @@ func (r *assetRepo) FindByTeam(ctx context.Context, id id.TeamID, pagination *us } func (r *assetRepo) init() { - i := r.client.CreateIndex(context.Background(), nil) + i := r.client.CreateIndex(context.Background(), []string{"team"}) if len(i) > 0 { log.Infof("mongo: %s: index created: %s", "asset", i) } diff --git a/internal/infrastructure/mongo/dataset.go b/internal/infrastructure/mongo/dataset.go index f802db5f..52a1cc0c 100644 --- a/internal/infrastructure/mongo/dataset.go +++ b/internal/infrastructure/mongo/dataset.go @@ -27,7 +27,7 @@ func NewDataset(client *mongodoc.Client) repo.Dataset { } func (r *datasetRepo) init() { - i := r.client.CreateIndex(context.Background(), nil) + i := r.client.CreateIndex(context.Background(), []string{"scene", "schema"}) if len(i) > 0 { log.Infof("mongo: %s: index created: %s", "dataset", i) } diff --git a/internal/infrastructure/mongo/dataset_schema.go b/internal/infrastructure/mongo/dataset_schema.go index 00860f6f..ba2d4d33 100644 --- a/internal/infrastructure/mongo/dataset_schema.go +++ b/internal/infrastructure/mongo/dataset_schema.go @@ -25,7 +25,7 @@ func NewDatasetSchema(client *mongodoc.Client) repo.DatasetSchema { } func (r *datasetSchemaRepo) init() { - i := r.client.CreateIndex(context.Background(), nil) + i := r.client.CreateIndex(context.Background(), []string{"scene"}) if len(i) > 0 { log.Infof("mongo: %s: index created: %s", "datasetSchema", i) } diff --git a/internal/infrastructure/mongo/layer.go b/internal/infrastructure/mongo/layer.go index 33eb7089..8475e80f 100644 --- a/internal/infrastructure/mongo/layer.go +++ b/internal/infrastructure/mongo/layer.go @@ -24,7 +24,7 @@ func NewLayer(client *mongodoc.Client) repo.Layer { } func (r *layerRepo) init() { - i := r.client.CreateIndex(context.Background(), nil) + i := r.client.CreateIndex(context.Background(), []string{"plugin", "extension", "scene", "group.layers", "tags.id", "tags.tags.id"}) if len(i) > 0 { log.Infof("mongo: %s: index created: %s", "layer", i) } diff --git a/internal/infrastructure/mongo/mongodoc/dataset.go b/internal/infrastructure/mongo/mongodoc/dataset.go index 3cfd9e08..5f36282b 100644 --- a/internal/infrastructure/mongo/mongodoc/dataset.go +++ b/internal/infrastructure/mongo/mongodoc/dataset.go @@ -7,13 +7,6 @@ import ( "github.com/reearth/reearth-backend/pkg/id" ) -type DatasetFieldDocument struct { - Field string - Type string - Value interface{} - Source string -} - type DatasetDocument struct { ID string Source string @@ -22,6 +15,13 @@ type DatasetDocument struct { Scene string } +type DatasetFieldDocument struct { + Field string + Type string + Value interface{} + Source string +} + type DatasetExtendedDocument struct { DatasetDocument Graph []*DatasetExtendedDocument diff --git a/internal/infrastructure/mongo/mongodoc/layer.go b/internal/infrastructure/mongo/mongodoc/layer.go index 5483b31e..f34b2a54 100644 --- a/internal/infrastructure/mongo/mongodoc/layer.go +++ b/internal/infrastructure/mongo/mongodoc/layer.go @@ -8,6 +8,30 @@ import ( "go.mongodb.org/mongo-driver/bson" ) +type LayerDocument struct { + ID string + Name string + Visible bool + Scene string + Plugin *string + Extension *string + Property *string + Infobox *LayerInfoboxDocument + Item *LayerItemDocument + Group *LayerGroupDocument + Tags LayerTagListDocument +} + +type LayerItemDocument struct { + LinkedDataset *string +} + +type LayerGroupDocument struct { + Layers []string + LinkedDatasetSchema *string + Root bool +} + type LayerInfoboxFieldDocument struct { ID string Plugin string @@ -28,30 +52,6 @@ type LayerTagDocument struct { type LayerTagListDocument []LayerTagDocument -type LayerItemDocument struct { - LinkedDataset *string -} - -type LayerGroupDocument struct { - Layers []string - LinkedDatasetSchema *string - Root bool -} - -type LayerDocument struct { - ID string - Name string - Visible bool - Scene string - Plugin *string - Extension *string - Property *string - Infobox *LayerInfoboxDocument - Item *LayerItemDocument - Group *LayerGroupDocument - Tags LayerTagListDocument -} - type LayerConsumer struct { Rows []*layer.Layer GroupRows []*layer.Group diff --git a/internal/infrastructure/mongo/mongodoc/scene.go b/internal/infrastructure/mongo/mongodoc/scene.go index fbb19a2b..01681580 100644 --- a/internal/infrastructure/mongo/mongodoc/scene.go +++ b/internal/infrastructure/mongo/mongodoc/scene.go @@ -10,6 +10,19 @@ import ( "github.com/reearth/reearth-backend/pkg/scene" ) +type SceneDocument struct { + ID string + Project string + Team string + RootLayer string + Widgets []SceneWidgetDocument + AlignSystem *WidgetAlignSystemDocument + Plugins []ScenePluginDocument + UpdateAt time.Time + Property string + Clusters []SceneClusterDocument +} + type SceneWidgetDocument struct { ID string Plugin string @@ -30,19 +43,6 @@ type SceneClusterDocument struct { Property string } -type SceneDocument struct { - ID string - Project string - Team string - RootLayer string - Widgets []SceneWidgetDocument - AlignSystem *WidgetAlignSystemDocument - Plugins []ScenePluginDocument - UpdateAt time.Time - Property string - Clusters []SceneClusterDocument -} - type SceneConsumer struct { Rows []*scene.Scene } diff --git a/internal/infrastructure/mongo/mongodoc/tag.go b/internal/infrastructure/mongo/mongodoc/tag.go index 11550237..3c270efb 100644 --- a/internal/infrastructure/mongo/mongodoc/tag.go +++ b/internal/infrastructure/mongo/mongodoc/tag.go @@ -9,6 +9,14 @@ import ( "github.com/reearth/reearth-backend/pkg/tag" ) +type TagDocument struct { + ID string + Label string + Scene string + Item *TagItemDocument + Group *TagGroupDocument +} + type TagItemDocument struct { Parent *string LinkedDatasetFieldID *string @@ -20,14 +28,6 @@ type TagGroupDocument struct { Tags []string } -type TagDocument struct { - ID string - Label string - Scene string - Item *TagItemDocument - Group *TagGroupDocument -} - type TagConsumer struct { Rows []*tag.Tag GroupRows []*tag.Group diff --git a/internal/infrastructure/mongo/mongodoc/team.go b/internal/infrastructure/mongo/mongodoc/team.go index 261d6188..1006322e 100644 --- a/internal/infrastructure/mongo/mongodoc/team.go +++ b/internal/infrastructure/mongo/mongodoc/team.go @@ -2,7 +2,7 @@ package mongodoc import ( "github.com/reearth/reearth-backend/pkg/id" - user1 "github.com/reearth/reearth-backend/pkg/user" + "github.com/reearth/reearth-backend/pkg/user" "go.mongodb.org/mongo-driver/bson" ) @@ -18,7 +18,7 @@ type TeamDocument struct { } type TeamConsumer struct { - Rows []*user1.Team + Rows []*user.Team } func (c *TeamConsumer) Consume(raw bson.Raw) error { @@ -38,7 +38,7 @@ func (c *TeamConsumer) Consume(raw bson.Raw) error { return nil } -func NewTeam(team *user1.Team) (*TeamDocument, string) { +func NewTeam(team *user.Team) (*TeamDocument, string) { membersDoc := map[string]TeamMemberDocument{} for user, r := range team.Members().Members() { membersDoc[user.String()] = TeamMemberDocument{ @@ -54,23 +54,23 @@ func NewTeam(team *user1.Team) (*TeamDocument, string) { }, id } -func (d *TeamDocument) Model() (*user1.Team, error) { +func (d *TeamDocument) Model() (*user.Team, error) { tid, err := id.TeamIDFrom(d.ID) if err != nil { return nil, err } - members := map[id.UserID]user1.Role{} + members := map[id.UserID]user.Role{} if d.Members != nil { - for user, member := range d.Members { - uid, err := id.UserIDFrom(user) + for uid, member := range d.Members { + uid, err := id.UserIDFrom(uid) if err != nil { return nil, err } - members[uid] = user1.Role(member.Role) + members[uid] = user.Role(member.Role) } } - return user1.NewTeam(). + return user.NewTeam(). ID(tid). Name(d.Name). Members(members). @@ -78,8 +78,8 @@ func (d *TeamDocument) Model() (*user1.Team, error) { Build() } -func NewTeams(teams []*user1.Team) ([]interface{}, []string) { - res := make([]interface{}, 0, len(teams)) +func NewTeams(teams []*user.Team) ([]*TeamDocument, []string) { + res := make([]*TeamDocument, 0, len(teams)) ids := make([]string, 0, len(teams)) for _, d := range teams { if d == nil { diff --git a/internal/infrastructure/mongo/plugin.go b/internal/infrastructure/mongo/plugin.go index ff19986e..948cb5bc 100644 --- a/internal/infrastructure/mongo/plugin.go +++ b/internal/infrastructure/mongo/plugin.go @@ -25,7 +25,7 @@ func NewPlugin(client *mongodoc.Client) repo.Plugin { } func (r *pluginRepo) init() { - i := r.client.CreateIndex(context.Background(), nil) + i := r.client.CreateIndex(context.Background(), []string{"scene"}) if len(i) > 0 { log.Infof("mongo: %s: index created: %s", "plugin", i) } diff --git a/internal/infrastructure/mongo/project.go b/internal/infrastructure/mongo/project.go index 3f81036d..006cf0a5 100644 --- a/internal/infrastructure/mongo/project.go +++ b/internal/infrastructure/mongo/project.go @@ -25,7 +25,7 @@ func NewProject(client *mongodoc.Client) repo.Project { } func (r *projectRepo) init() { - i := r.client.CreateIndex(context.Background(), []string{"alias"}) + i := r.client.CreateIndex(context.Background(), []string{"alias", "team"}) if len(i) > 0 { log.Infof("mongo: %s: index created: %s", "project", i) } diff --git a/internal/infrastructure/mongo/property.go b/internal/infrastructure/mongo/property.go index ed40e2fa..1fb1bbc6 100644 --- a/internal/infrastructure/mongo/property.go +++ b/internal/infrastructure/mongo/property.go @@ -23,7 +23,7 @@ func NewProperty(client *mongodoc.Client) repo.Property { } func (r *propertyRepo) init() { - i := r.client.CreateIndex(context.Background(), nil) + i := r.client.CreateIndex(context.Background(), []string{"scene", "schema"}) if len(i) > 0 { log.Infof("mongo: %s: index created: %s", "property", i) } diff --git a/internal/infrastructure/mongo/scene.go b/internal/infrastructure/mongo/scene.go index b27cb323..af9a2416 100644 --- a/internal/infrastructure/mongo/scene.go +++ b/internal/infrastructure/mongo/scene.go @@ -25,7 +25,7 @@ func NewScene(client *mongodoc.Client) repo.Scene { } func (r *sceneRepo) init() { - i := r.client.CreateIndex(context.Background(), nil) + i := r.client.CreateIndex(context.Background(), []string{"project"}) if len(i) > 0 { log.Infof("mongo: %s: index created: %s", "scene", i) } diff --git a/internal/infrastructure/mongo/tag.go b/internal/infrastructure/mongo/tag.go index 6717cc6f..5aed97d8 100644 --- a/internal/infrastructure/mongo/tag.go +++ b/internal/infrastructure/mongo/tag.go @@ -24,7 +24,7 @@ func NewTag(client *mongodoc.Client) repo.Tag { } func (r *tagRepo) init() { - i := r.client.CreateIndex(context.Background(), nil) + i := r.client.CreateIndex(context.Background(), []string{"scene", "group.tags", "item.parent"}) if len(i) > 0 { log.Infof("mongo: %s: index created: %s", "tag", i) } diff --git a/internal/infrastructure/mongo/team.go b/internal/infrastructure/mongo/team.go index 9249fb6d..336e366b 100644 --- a/internal/infrastructure/mongo/team.go +++ b/internal/infrastructure/mongo/team.go @@ -69,7 +69,11 @@ func (r *teamRepo) SaveAll(ctx context.Context, teams []*user.Team) error { return nil } docs, ids := mongodoc.NewTeams(teams) - return r.client.SaveAll(ctx, ids, docs) + docs2 := make([]interface{}, 0, len(teams)) + for _, d := range docs { + docs2 = append(docs2, d) + } + return r.client.SaveAll(ctx, ids, docs2) } func (r *teamRepo) Remove(ctx context.Context, id id.TeamID) error {