-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
tweaks generators to complete CRUD (#36)
- Loading branch information
1 parent
abacec5
commit 8c9dfb8
Showing
13 changed files
with
150 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package presenters | ||
|
||
import ( | ||
"gitlab.cee.redhat.com/ocm/ensemble/pkg/api" | ||
"gitlab.cee.redhat.com/ocm/ensemble/pkg/api/openapi" | ||
"gitlab.cee.redhat.com/ocm/ensemble/pkg/util" | ||
) | ||
|
||
func Convert{{.Kind}}({{.KindLowerSingular}} openapi.{{.Kind}}) *api.{{.Kind}} { | ||
c := &api.{{.Kind}}{ | ||
Meta: api.Meta{ | ||
ID: util.NilToEmptyString({{.KindLowerSingular}}.Id), | ||
}, | ||
} | ||
|
||
if {{.KindLowerSingular}}.CreatedAt != nil { | ||
c.CreatedAt = *{{.KindLowerSingular}}.CreatedAt | ||
c.UpdatedAt = *{{.KindLowerSingular}}.UpdatedAt | ||
} | ||
|
||
return c | ||
} | ||
|
||
func Present{{.Kind}}({{.KindLowerSingular}} *api.{{.Kind}}) openapi.{{.Kind}} { | ||
reference := PresentReference({{.KindLowerSingular}}.ID, {{.KindLowerSingular}}) | ||
|
||
reference.CreatedAt = PresentTime({{.KindLowerSingular}}.CreatedAt) | ||
reference.UpdatedAt = PresentTime({{.KindLowerSingular}}.UpdatedAt) | ||
|
||
return openapi.{{.Kind}}{ | ||
Id: reference.Id, | ||
CreatedAt: PresentTime(*reference.CreatedAt), | ||
UpdatedAt: PresentTime(*reference.UpdatedAt), | ||
Kind: reference.Kind, | ||
Href: reference.Href, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package environments | ||
|
||
import ( | ||
"gitlab.cee.redhat.com/ocm/ensemble/pkg/dao" | ||
"gitlab.cee.redhat.com/ocm/ensemble/pkg/services" | ||
) | ||
|
||
type {{.Kind}}ServiceLocator func() services.{{.Kind}}Service | ||
|
||
func New{{.Kind}}ServiceLocator(env *Env) {{.Kind}}ServiceLocator { | ||
return func() services.{{.Kind}}Service { | ||
return services.New{{.Kind}}Service( | ||
dao.New{{.Kind}}Dao(&env.Database.SessionFactory), | ||
env.Services.Events(), | ||
) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package factories | ||
|
||
import ( | ||
"context" | ||
"gitlab.cee.redhat.com/ocm/ensemble/cmd/ensemble/environments" | ||
"gitlab.cee.redhat.com/ocm/ensemble/pkg/api" | ||
) | ||
|
||
func (f *Factories) New{{.Kind}}(id string) (*api.{{.Kind}}, error) { | ||
{{.Kind}}Service := environments.Environment().Services.{{.KindPlural}}() | ||
|
||
{{.Kind}} := &api.{{.Kind}}{ | ||
Meta: api.Meta{ID: id}, | ||
} | ||
|
||
sub, err := {{.Kind}}Service.Create(context.Background(), {{.Kind}}) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return sub, nil | ||
} | ||
|
||
func (f *Factories) New{{.Kind}}List(name string, count int) ([]*api.{{.Kind}}, error) { | ||
{{.KindPlural}} := []*api.{{.Kind}}{} | ||
for i := 1; i <= count; i++ { | ||
c, _ := f.New{{.Kind}}(f.NewID()) | ||
{{.KindPlural}} = append({{.KindPlural}}, c) | ||
} | ||
return {{.KindPlural}}, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters