Skip to content

Commit

Permalink
use pascal plural name for generated interactors
Browse files Browse the repository at this point in the history
  • Loading branch information
EthanThatOneKid committed Nov 23, 2023
1 parent 89b6c6c commit 04bbf1c
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 5 deletions.
1 change: 1 addition & 0 deletions api/openapi/interactors/interactors.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
"interactors": [
{
"pascalName": "Event",
"pascalPluralName": "Events",
"camelName": "event",
"kabobPluralName": "events"
}
Expand Down
4 changes: 2 additions & 2 deletions api/openapi/interactors/interactors_generated.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ func useCRUDL(service *web.Service, optionFns ...crudlOptionFn) {
}

// UseEvent uses a generated Event interactor.
func UseEvent(service *web.Service, store api.Store) {
func UseEvents(service *web.Service, store api.Store) {
useCRUDL(
service,
withPrefix("/events"),
Expand Down Expand Up @@ -118,5 +118,5 @@ func UseEvent(service *web.Service, store api.Store) {

// UseAll uses all interactors.
func UseAll(service *web.Service, store api.Store) {
UseEvent(service, store)
UseEvents(service, store)
}
10 changes: 7 additions & 3 deletions cli/interactors_generator/interactors_generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ type InteractorConfig struct {
PascalName string `json:"pascalName"`

// PascalPluralName is the PascalCase plural name of the interactor.
// PascalPluralName string `json:"pascalPluralName"`
PascalPluralName string `json:"pascalPluralName"`

// CamelName is the camelCase name of the interactor.
CamelName string `json:"camelName"`
Expand All @@ -72,7 +72,7 @@ func (c *InteractorConfig) Render(result *string, storePackage string) error {
b.WriteString(" uses a generated ")
b.WriteString(c.PascalName)
b.WriteString(" interactor.\n")
b.WriteString(fmt.Sprintf("func Use%s(service *web.Service, store %s.Store) {\n", c.PascalName, storePackage))
b.WriteString(fmt.Sprintf("func Use%s(service *web.Service, store %s.Store) {\n", c.PascalPluralName, storePackage))
b.WriteString("\tuseCRUDL(\n")
b.WriteString("\t\tservice,\n")
b.WriteString("\t\twithPrefix(\"/")
Expand Down Expand Up @@ -150,6 +150,10 @@ func (c *Config) Render(result *string) error {
return fmt.Errorf("interactor %s has no pascalName", interactorConfig.PascalName)
}

if interactorConfig.PascalPluralName == "" {
return fmt.Errorf("interactor %s has no pascalPluralName", interactorConfig.PascalName)
}

if interactorConfig.KabobPluralName == "" {
return fmt.Errorf("interactor %s has no kabobPluralName", interactorConfig.PascalName)
}
Expand All @@ -172,7 +176,7 @@ func (c *Config) Render(result *string) error {
b.WriteString(c.StorePackage)
b.WriteString(".Store) {\n")
for _, interactorConfig := range c.Interactors {
b.WriteString(fmt.Sprintf("\tUse%s(service, store)\n", interactorConfig.PascalName))
b.WriteString(fmt.Sprintf("\tUse%s(service, store)\n", interactorConfig.PascalPluralName))
}
b.WriteString("}\n")

Expand Down

0 comments on commit 04bbf1c

Please sign in to comment.