Skip to content

Commit

Permalink
fix(server): auth server request indexes
Browse files Browse the repository at this point in the history
  • Loading branch information
rot1024 committed Sep 20, 2022
1 parent 59f8a85 commit 430da0a
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 10 deletions.
2 changes: 1 addition & 1 deletion server/go.mod
Expand Up @@ -23,7 +23,7 @@ require (
github.com/paulmach/go.geojson v1.4.0
github.com/pkg/errors v0.9.1
github.com/ravilushqa/otelgqlgen v0.8.0
github.com/reearth/reearthx v0.0.0-20220831124713-1b1373700421
github.com/reearth/reearthx v0.0.0-20220920100400-54da87c8211a
github.com/samber/lo v1.27.0
github.com/sendgrid/sendgrid-go v3.11.1+incompatible
github.com/sirupsen/logrus v1.8.1
Expand Down
2 changes: 2 additions & 0 deletions server/go.sum
Expand Up @@ -418,6 +418,8 @@ github.com/ravilushqa/otelgqlgen v0.8.0 h1:x48k+D1GMgm87xhMO2Lekrr9YGzFbpG3yijn9
github.com/ravilushqa/otelgqlgen v0.8.0/go.mod h1:6JO5YO2iY4POC7R6yB/L/RKXCcyISL8qQt5NnHOhh0o=
github.com/reearth/reearthx v0.0.0-20220831124713-1b1373700421 h1:fQ/f3Vmcv3BMIArGKLDV+AcXaJZOLJu8DZDsVzczrmg=
github.com/reearth/reearthx v0.0.0-20220831124713-1b1373700421/go.mod h1:YZMXO1RhQ5fFL0GIOFvJq2GNskW7w+xoW4Zfu2QUXhw=
github.com/reearth/reearthx v0.0.0-20220920100400-54da87c8211a h1:c1wckKanJD8e2Zi2FiKBheNHaT9ZJ5fqUjbTYlBlc9k=
github.com/reearth/reearthx v0.0.0-20220920100400-54da87c8211a/go.mod h1:YZMXO1RhQ5fFL0GIOFvJq2GNskW7w+xoW4Zfu2QUXhw=
github.com/robertkrimen/godocdown v0.0.0-20130622164427-0bfa04905481/go.mod h1:C9WhFzY47SzYBIvzFqSvHIR6ROgDo4TtdTuRaOMjF/s=
github.com/rogpeppe/fastuuid v1.2.0/go.mod h1:jVj6XXZzXRy/MSR5jhDC/2q6DgLz+nrA6LYCDYWNEvQ=
github.com/rogpeppe/go-internal v1.1.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4=
Expand Down
5 changes: 3 additions & 2 deletions server/internal/app/repo.go
Expand Up @@ -33,9 +33,10 @@ func initReposAndGateways(ctx context.Context, conf *Config, debug bool) (*repo.
SetMonitor(otelmongo.NewMonitor()),
)
if err != nil {
log.Fatalf("repo initialization error: %+v\n", err)
log.Fatalf("mongo error: %+v\n", err)
}
repos, err := mongorepo.New(ctx, client, "reearth")

repos, err := mongorepo.New(ctx, client.Database("reearth"))
if err != nil {
log.Fatalf("Failed to init mongo: %+v\n", err)
}
Expand Down
18 changes: 11 additions & 7 deletions server/internal/infrastructure/mongo/container.go
Expand Up @@ -9,25 +9,24 @@ import (
"github.com/reearth/reearth/server/pkg/user"
"github.com/reearth/reearthx/authserver"
"github.com/reearth/reearthx/mongox"
"github.com/reearth/reearthx/util"
"go.mongodb.org/mongo-driver/bson"
"go.mongodb.org/mongo-driver/mongo"
)

func New(ctx context.Context, mc *mongo.Client, databaseName string) (*repo.Container, error) {
if databaseName == "" {
databaseName = "reearth"
}

db := mc.Database(databaseName)
func New(ctx context.Context, db *mongo.Database) (*repo.Container, error) {
lock, err := NewLock(db.Collection("locks"))
if err != nil {
return nil, err
}

client := mongox.NewClientWithDatabase(db)

authRequest := authserver.NewMongo(client.WithCollection("authRequest"))

c := &repo.Container{
Asset: NewAsset(client),
AuthRequest: authserver.NewMongo(client.WithCollection("authRequest")),
AuthRequest: authRequest,
Config: NewConfig(db.Collection("config"), lock),
DatasetSchema: NewDatasetSchema(client),
Dataset: NewDataset(client),
Expand All @@ -46,6 +45,11 @@ func New(ctx context.Context, mc *mongo.Client, databaseName string) (*repo.Cont
Lock: lock,
}

// init
if err := util.Try(authRequest.Init); err != nil {
return nil, err
}

// migration
m := migration.Client{Client: client, Config: c.Config}
if err := m.Migrate(ctx); err != nil {
Expand Down

0 comments on commit 430da0a

Please sign in to comment.