Skip to content

Commit

Permalink
feature: #270 Added container to new projection signature
Browse files Browse the repository at this point in the history
  • Loading branch information
akeemphilbert committed Jul 22, 2023
1 parent 8a48ed0 commit 603ee0f
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 43 deletions.
2 changes: 1 addition & 1 deletion controllers/rest/api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ func TestRESTAPI_DefaultProjectionRegisteredBefore(t *testing.T) {
t.Fatalf("un expected error loading spec '%s'", err)
}
_, gormDB, _, err := tapi.SQLConnectionFromConfig(tapi.Config.Database)
gormProjection, err := projections.NewProjection(context.TODO(), gormDB, tapi.EchoInstance().Logger)
gormProjection, err := projections.NewProjection(context.TODO(), nil, gormDB, tapi.EchoInstance().Logger)
if err != nil {
t.Fatalf("error setting up gorm projection")
}
Expand Down
2 changes: 1 addition & 1 deletion controllers/rest/global_initializers.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ func DefaultProjection(ctxt context.Context, tapi Container, swagger *openapi3.S
//setup default projection if gormDB is configured
defaultProjection, _ := api.GetProjection("Default")
if defaultProjection == nil {
defaultProjection, err = projections.NewProjection(ctxt, api.gormConnection, api.EchoInstance().Logger)
defaultProjection, err = projections.NewProjection(ctxt, tapi, api.gormConnection, api.EchoInstance().Logger)
api.RegisterProjection("Default", defaultProjection)

//---- TODO clean up setting up schemas here
Expand Down
2 changes: 1 addition & 1 deletion model/content_entity_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1049,7 +1049,7 @@ func TestContentEntity_CreateWithCollection(t *testing.T) {
}

var model interface{}
projection, err := projections.NewProjection(context.Background(), nil, api.EchoInstance().Logger)
projection, err := projections.NewProjection(context.Background(), nil, nil, api.EchoInstance().Logger)
if err != nil {
t.Fatal(err)
}
Expand Down
3 changes: 2 additions & 1 deletion projections/gorm.go
Original file line number Diff line number Diff line change
Expand Up @@ -980,9 +980,10 @@ func NewGORMRepository(ctx context.Context, container weos.Container, name strin
}

//NewProjection creates an instance of the projection
func NewProjection(ctx context.Context, db *gorm.DB, logger weos.Log) (*GORMDB, error) {
func NewProjection(ctx context.Context, container weos.Container, db *gorm.DB, logger weos.Log) (*GORMDB, error) {

projection := &GORMDB{
container: container,
logger: logger,
SchemaBuilder: make(map[string]ds.Builder),
keys: make(map[string]map[string]interface{}),
Expand Down
18 changes: 9 additions & 9 deletions projections/gorm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ func TestGORMDB_GORMModel(t *testing.T) {
}
schemas := rest.CreateSchema(context.Background(), api.EchoInstance(), api.Swagger)
entityFactory1 := new(model.DefaultEntityFactory).FromSchemaAndBuilder(contentType1, api.Swagger.Components.Schemas[contentType1].Value, schemas[contentType1])
projection, err := projections.NewProjection(context.Background(), gormDB, api.EchoInstance().Logger)
projection, err := projections.NewProjection(context.Background(), nil, gormDB, api.EchoInstance().Logger)
if err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -148,7 +148,7 @@ func TestGORMDB_GORMModel(t *testing.T) {
t.Errorf("unexpected error marshalling entity; %s", err)
}
entityFactory1 := new(model.DefaultEntityFactory).FromSchemaAndBuilder(contentType1, api.Swagger.Components.Schemas[contentType1].Value, nil)
projection, err := projections.NewProjection(context.Background(), gormDB, api.EchoInstance().Logger)
projection, err := projections.NewProjection(context.Background(), nil, gormDB, api.EchoInstance().Logger)
if err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -218,7 +218,7 @@ func TestGORMDB_GORMModel(t *testing.T) {
entityFactory2 := new(model.DefaultEntityFactory).FromSchemaAndBuilder("Blog", api.Swagger.Components.Schemas["Blog"].Value, schemas["Blog"])
entityFactory3 := new(model.DefaultEntityFactory).FromSchemaAndBuilder("Author", api.Swagger.Components.Schemas["Author"].Value, schemas["Author"])
entityFactory4 := new(model.DefaultEntityFactory).FromSchemaAndBuilder("Category", api.Swagger.Components.Schemas["Category"].Value, schemas["Category"])
projection, err := projections.NewProjection(context.Background(), gormDB, api.EchoInstance().Logger)
projection, err := projections.NewProjection(context.Background(), nil, gormDB, api.EchoInstance().Logger)
if err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -289,7 +289,7 @@ func TestGORMDB_GORMModel(t *testing.T) {
}
schemas := rest.CreateSchema(context.Background(), api.EchoInstance(), api.Swagger)
entityFactory1 := new(model.DefaultEntityFactory).FromSchemaAndBuilder(contentType1, api.Swagger.Components.Schemas[contentType1].Value, schemas[contentType1])
projection, err := projections.NewProjection(context.Background(), gormDB, api.EchoInstance().Logger)
projection, err := projections.NewProjection(context.Background(), nil, gormDB, api.EchoInstance().Logger)
if err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -338,7 +338,7 @@ func TestGORMDB_GORMModels(t *testing.T) {
if err != nil {
t.Fatalf("unexpected error setting up api: %s", err)
}
projection, err := projections.NewProjection(context.Background(), gormDB, api.EchoInstance().Logger)
projection, err := projections.NewProjection(context.Background(), nil, gormDB, api.EchoInstance().Logger)
if err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -518,7 +518,7 @@ func TestGORMDB_Persist(t *testing.T) {
if err != nil {
t.Fatalf("unexpected error setting up api: %s", err)
}
projection, err := projections.NewProjection(context.Background(), gormDB, api.EchoInstance().Logger)
projection, err := projections.NewProjection(context.Background(), nil, gormDB, api.EchoInstance().Logger)
if err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -589,7 +589,7 @@ func TestGORMDB_Remove(t *testing.T) {
if err != nil {
t.Fatalf("unexpected error setting up api: %s", err)
}
projection, err := projections.NewProjection(context.Background(), gormDB, api.EchoInstance().Logger)
projection, err := projections.NewProjection(context.Background(), nil, gormDB, api.EchoInstance().Logger)
if err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -673,7 +673,7 @@ func TestGORMDB_GetByKey(t *testing.T) {
if err != nil {
t.Fatalf("unexpected error setting up api: %s", err)
}
projection, err := projections.NewProjection(context.Background(), gormDB, api.EchoInstance().Logger)
projection, err := projections.NewProjection(context.Background(), nil, gormDB, api.EchoInstance().Logger)
if err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -744,7 +744,7 @@ func TestGORMDB_GetContentEntity(t *testing.T) {
if err != nil {
t.Fatalf("unexpected error setting up api: %s", err)
}
projection, err := projections.NewProjection(context.Background(), gormDB, api.EchoInstance().Logger)
projection, err := projections.NewProjection(context.Background(), nil, gormDB, api.EchoInstance().Logger)
if err != nil {
t.Fatal(err)
}
Expand Down
60 changes: 30 additions & 30 deletions projections/projections_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ components:
t.Fatalf("error loading api config '%s'", err)
}

p, err := projections.NewProjection(context.Background(), gormDB, api.EchoInstance().Logger)
p, err := projections.NewProjection(context.Background(), nil, gormDB, api.EchoInstance().Logger)
if err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -307,7 +307,7 @@ components:

//automigrate table again to ensure no issue on multiple migrates
for i := 0; i < 10; i++ {
_, err = projections.NewProjection(context.Background(), nil, nil)
_, err = projections.NewProjection(context.Background(), nil, nil, nil)
if err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -408,7 +408,7 @@ components:
if err != nil {
t.Fatalf("error loading api config '%s'", err)
}
p, err := projections.NewProjection(context.Background(), gormDB, api.EchoInstance().Logger)
p, err := projections.NewProjection(context.Background(), nil, gormDB, api.EchoInstance().Logger)
if err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -535,7 +535,7 @@ components:
t.Fatalf("error loading api config '%s'", err)
}

p, err := projections.NewProjection(context.Background(), gormDB, api.EchoInstance().Logger)
p, err := projections.NewProjection(context.Background(), nil, gormDB, api.EchoInstance().Logger)
if err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -629,7 +629,7 @@ components:
t.Fatalf("error loading api config '%s'", err)
}

p, err := projections.NewProjection(context.Background(), gormDB, api.EchoInstance().Logger)
p, err := projections.NewProjection(context.Background(), nil, gormDB, api.EchoInstance().Logger)
if err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -750,7 +750,7 @@ components:
t.Fatalf("error loading api config '%s'", err)
}

p, err := projections.NewProjection(context.Background(), gormDB, api.EchoInstance().Logger)
p, err := projections.NewProjection(context.Background(), nil, gormDB, api.EchoInstance().Logger)
if err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -814,7 +814,7 @@ components:

//automigrate table again to ensure no issue on multiple migrates
for i := 0; i < 20; i++ {
_, err = projections.NewProjection(context.Background(), nil, nil)
_, err = projections.NewProjection(context.Background(), nil, nil, nil)
if err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -902,7 +902,7 @@ components:
}

schemes := rest.CreateSchema(context.Background(), echo.New(), api.Swagger)
p, err := projections.NewProjection(context.Background(), gormDB, api.EchoInstance().Logger)
p, err := projections.NewProjection(context.Background(), nil, gormDB, api.EchoInstance().Logger)
if err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -1018,7 +1018,7 @@ components:
}

schemes := rest.CreateSchema(context.Background(), echo.New(), api.Swagger)
p, err := projections.NewProjection(context.Background(), gormDB, api.EchoInstance().Logger)
p, err := projections.NewProjection(context.Background(), nil, gormDB, api.EchoInstance().Logger)
if err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -1187,7 +1187,7 @@ components:
}

schemes := rest.CreateSchema(context.Background(), echo.New(), api.Swagger)
p, err := projections.NewProjection(context.Background(), gormDB, api.EchoInstance().Logger)
p, err := projections.NewProjection(context.Background(), nil, gormDB, api.EchoInstance().Logger)
if err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -1286,7 +1286,7 @@ components:
}

schemes := rest.CreateSchema(context.Background(), echo.New(), api.Swagger)
p, err := projections.NewProjection(context.Background(), gormDB, api.EchoInstance().Logger)
p, err := projections.NewProjection(context.Background(), nil, gormDB, api.EchoInstance().Logger)
if err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -1462,7 +1462,7 @@ components:
}

schemes := rest.CreateSchema(context.Background(), echo.New(), api.Swagger)
p, err := projections.NewProjection(context.Background(), gormDB, api.EchoInstance().Logger)
p, err := projections.NewProjection(context.Background(), nil, gormDB, api.EchoInstance().Logger)
if err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -1594,7 +1594,7 @@ components:
}

schemes := rest.CreateSchema(context.Background(), echo.New(), api.Swagger)
p, err := projections.NewProjection(context.Background(), gormDB, api.EchoInstance().Logger)
p, err := projections.NewProjection(context.Background(), nil, gormDB, api.EchoInstance().Logger)
if err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -1751,7 +1751,7 @@ components:
t.Fatalf("error loading api config '%s'", err)
}

p, err := projections.NewProjection(context.Background(), gormDB, api.EchoInstance().Logger)
p, err := projections.NewProjection(context.Background(), nil, gormDB, api.EchoInstance().Logger)
if err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -1889,7 +1889,7 @@ components:
gormDB.Logger.LogMode(logger.Info)

schemes := rest.CreateSchema(context.Background(), echo.New(), api.Swagger)
p, err := projections.NewProjection(context.Background(), gormDB, api.EchoInstance().Logger)
p, err := projections.NewProjection(context.Background(), nil, gormDB, api.EchoInstance().Logger)
if err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -2027,7 +2027,7 @@ components:
t.Fatalf("error loading api config '%s'", err)
}

p, err := projections.NewProjection(context.Background(), gormDB, api.EchoInstance().Logger)
p, err := projections.NewProjection(context.Background(), nil, gormDB, api.EchoInstance().Logger)
if err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -2147,7 +2147,7 @@ components:
}

schemes := rest.CreateSchema(context.Background(), echo.New(), api.Swagger)
p, err := projections.NewProjection(context.Background(), gormDB, api.EchoInstance().Logger)
p, err := projections.NewProjection(context.Background(), nil, gormDB, api.EchoInstance().Logger)
if err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -2347,7 +2347,7 @@ components:
}

schemes := rest.CreateSchema(context.Background(), echo.New(), api.Swagger)
p, err := projections.NewProjection(context.Background(), gormDB, api.EchoInstance().Logger)
p, err := projections.NewProjection(context.Background(), nil, gormDB, api.EchoInstance().Logger)
if err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -2941,7 +2941,7 @@ components:
t.Fatalf("error loading api config '%s'", err)
}

p, err := projections.NewProjection(context.Background(), gormDB, api.EchoInstance().Logger)
p, err := projections.NewProjection(context.Background(), nil, gormDB, api.EchoInstance().Logger)
if err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -3043,7 +3043,7 @@ components:
t.Fatalf("error loading api config '%s'", err)
}

p, err = projections.NewProjection(context.Background(), gormDB, api.EchoInstance().Logger)
p, err = projections.NewProjection(context.Background(), nil, gormDB, api.EchoInstance().Logger)
if err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -3161,7 +3161,7 @@ components:
t.Fatalf("error loading api config '%s'", err)
}

p, err := projections.NewProjection(context.Background(), gormDB, api.EchoInstance().Logger)
p, err := projections.NewProjection(context.Background(), nil, gormDB, api.EchoInstance().Logger)
if err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -3268,7 +3268,7 @@ components:
t.Fatalf("error loading api config '%s'", err)
}

p, err = projections.NewProjection(context.Background(), gormDB, api.EchoInstance().Logger)
p, err = projections.NewProjection(context.Background(), nil, gormDB, api.EchoInstance().Logger)
if err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -3389,7 +3389,7 @@ components:
t.Fatalf("error loading api config '%s'", err)
}

p, err := projections.NewProjection(context.Background(), gormDB, api.EchoInstance().Logger)
p, err := projections.NewProjection(context.Background(), nil, gormDB, api.EchoInstance().Logger)
if err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -3480,7 +3480,7 @@ components:
t.Fatalf("error loading api config '%s'", err)
}

p, err = projections.NewProjection(context.Background(), gormDB, api.EchoInstance().Logger)
p, err = projections.NewProjection(context.Background(), nil, gormDB, api.EchoInstance().Logger)
if err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -3552,7 +3552,7 @@ components:
t.Fatalf("error loading api config '%s'", err)
}

p, err := projections.NewProjection(context.Background(), gormDB, api.EchoInstance().Logger)
p, err := projections.NewProjection(context.Background(), nil, gormDB, api.EchoInstance().Logger)
if err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -3642,7 +3642,7 @@ components:
t.Fatalf("error loading api config '%s'", err)
}

p, err = projections.NewProjection(context.Background(), gormDB, api.EchoInstance().Logger)
p, err = projections.NewProjection(context.Background(), nil, gormDB, api.EchoInstance().Logger)
if err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -3750,7 +3750,7 @@ components:
t.Fatalf("error loading api config '%s'", err)
}

p, err := projections.NewProjection(context.Background(), gormDB, api.EchoInstance().Logger)
p, err := projections.NewProjection(context.Background(), nil, gormDB, api.EchoInstance().Logger)
if err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -3847,7 +3847,7 @@ components:
t.Fatalf("error loading api config '%s'", err)
}
schemes := rest.CreateSchema(context.Background(), echo.New(), api.Swagger)
p, err := projections.NewProjection(context.Background(), gormDB, api.EchoInstance().Logger)
p, err := projections.NewProjection(context.Background(), nil, gormDB, api.EchoInstance().Logger)
if err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -3966,7 +3966,7 @@ components:
}

schemes := rest.CreateSchema(context.Background(), echo.New(), api.Swagger)
p, err := projections.NewProjection(context.Background(), gormDB, api.EchoInstance().Logger)
p, err := projections.NewProjection(context.Background(), nil, gormDB, api.EchoInstance().Logger)
if err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -4102,7 +4102,7 @@ components:
t.Fatalf("error loading api config '%s'", err)
}

p, err := projections.NewProjection(context.Background(), gormDB, api.EchoInstance().Logger)
p, err := projections.NewProjection(context.Background(), nil, gormDB, api.EchoInstance().Logger)
if err != nil {
t.Fatal(err)
}
Expand Down

0 comments on commit 603ee0f

Please sign in to comment.