From 04bbf1c3943f6a0ca6f5ec9d2ce3062b72983baf Mon Sep 17 00:00:00 2001 From: EthanThatOneKid <31261035+EthanThatOneKid@users.noreply.github.com> Date: Thu, 23 Nov 2023 00:06:18 -0800 Subject: [PATCH] use pascal plural name for generated interactors --- api/openapi/interactors/interactors.json | 1 + api/openapi/interactors/interactors_generated.go | 4 ++-- cli/interactors_generator/interactors_generator.go | 10 +++++++--- 3 files changed, 10 insertions(+), 5 deletions(-) diff --git a/api/openapi/interactors/interactors.json b/api/openapi/interactors/interactors.json index cfa930e..f685fa8 100644 --- a/api/openapi/interactors/interactors.json +++ b/api/openapi/interactors/interactors.json @@ -12,6 +12,7 @@ "interactors": [ { "pascalName": "Event", + "pascalPluralName": "Events", "camelName": "event", "kabobPluralName": "events" } diff --git a/api/openapi/interactors/interactors_generated.go b/api/openapi/interactors/interactors_generated.go index 032af0c..356a8e0 100644 --- a/api/openapi/interactors/interactors_generated.go +++ b/api/openapi/interactors/interactors_generated.go @@ -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"), @@ -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) } diff --git a/cli/interactors_generator/interactors_generator.go b/cli/interactors_generator/interactors_generator.go index f0b141a..79b7e0d 100644 --- a/cli/interactors_generator/interactors_generator.go +++ b/cli/interactors_generator/interactors_generator.go @@ -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"` @@ -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(\"/") @@ -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) } @@ -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")