From 63900d258ae92faa4faf14e834021347f202d8a1 Mon Sep 17 00:00:00 2001 From: Alex Herring Date: Sun, 22 May 2022 10:41:04 -0400 Subject: [PATCH 01/10] 204 improvements (#68) * return 204 on nil error response * allow void view actions * fix controller test for 204 nil error response * Fix `TestEmptyActionWithView` --- runtime/generator/controller/controller.gotext | 2 ++ runtime/generator/controller/controller_test.go | 10 +++++----- runtime/generator/controller/state.go | 16 ++++++++++------ 3 files changed, 17 insertions(+), 11 deletions(-) diff --git a/runtime/generator/controller/controller.gotext b/runtime/generator/controller/controller.gotext index 825de64d..05759186 100644 --- a/runtime/generator/controller/controller.gotext +++ b/runtime/generator/controller/controller.gotext @@ -118,6 +118,8 @@ func ({{$action.Short}} *{{ $.Pascal }}{{$action.Pascal}}Action) handler(httpReq {{- if $action.RespondJSON }} {{- if $action.Results.Result }} JSON: response.JSON({{ $action.Results.Result }}), + {{- else if $action.Results.IsOnlyError }} + JSON: response.Status(204), {{- else }} JSON: response.Status(200).Set("Content-Type", "application/json"), {{- end }} diff --git a/runtime/generator/controller/controller_test.go b/runtime/generator/controller/controller_test.go index 9c925bc6..82b9558b 100644 --- a/runtime/generator/controller/controller_test.go +++ b/runtime/generator/controller/controller_test.go @@ -951,15 +951,14 @@ func TestNestedResource(t *testing.T) { res, err = server.PatchJSON("/users/10", bytes.NewBufferString(`{"name": "matt", "age": 10}`)) is.NoErr(err) is.NoErr(res.Expect(` - HTTP/1.1 200 OK - Content-Type: application/json + HTTP/1.1 204 No Content + Content-Length: 0 Date: Fri, 31 Dec 2021 00:00:00 GMT `)) res, err = server.DeleteJSON("/users/10", nil) is.NoErr(err) is.NoErr(res.Expect(` - HTTP/1.1 200 OK - Content-Type: application/json + HTTP/1.1 204 No Content Date: Fri, 31 Dec 2021 00:00:00 GMT `)) } @@ -1896,11 +1895,11 @@ func TestWorkingChangeWorking(t *testing.T) { } func TestEmptyActionWithView(t *testing.T) { - t.SkipNow() is := is.New(t) ctx := context.Background() dir := t.TempDir() bud := budtest.New(dir) + bud.NodeModules["svelte"] = version.Svelte bud.Files["controller/controller.go"] = ` package controller type Controller struct {} @@ -1912,6 +1911,7 @@ func TestEmptyActionWithView(t *testing.T) { app, err := project.Build(ctx) is.NoErr(err) is.NoErr(app.Exists("bud/.app/view/view.go")) + is.NoErr(app.Exists("bud/.app/controller/controller.go")) is.NoErr(app.Exists("bud/.app/main.go")) server, err := app.Start(ctx) is.NoErr(err) diff --git a/runtime/generator/controller/state.go b/runtime/generator/controller/state.go index 158cf940..b0a6a533 100644 --- a/runtime/generator/controller/state.go +++ b/runtime/generator/controller/state.go @@ -159,14 +159,13 @@ func isList(dataType string) bool { func (results ActionResults) ViewResult() string { propsKey := results.propsKey() - if propsKey == "" { - return results.Result() - } out := new(strings.Builder) out.WriteString(`map[string]interface{}{`) - out.WriteString(strconv.Quote(propsKey)) - out.WriteString(":") - out.WriteString(results.Result()) + if propsKey != "" { + out.WriteString(strconv.Quote(propsKey)) + out.WriteString(":") + out.WriteString(results.Result()) + } out.WriteString(`},`) return out.String() } @@ -199,6 +198,11 @@ func (results ActionResults) Error() string { return "" } +// Error expression is only return +func (results ActionResults) IsOnlyError() bool { + return len(results) == 1 && results[0].IsError +} + // ActionResult struct type ActionResult struct { Name string From c491a3e0d6d0b4713af1f173ed50db3049f18ff7 Mon Sep 17 00:00:00 2001 From: syke99 Date: Sun, 22 May 2022 10:41:14 -0500 Subject: [PATCH 02/10] support for Windows builds in install step --- Makefile | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/Makefile b/Makefile index ece393ca..178769d9 100644 --- a/Makefile +++ b/Makefile @@ -9,7 +9,13 @@ precommit: test.dev install: go mod tidy npm install +ifeq ($(OS), Windows_NT) + cd livebud + npm install + cd .. +else (cd livebud && npm install) +endif ## # Examples From a6a8b1202ceff372771e5b50376d3cc3261918a3 Mon Sep 17 00:00:00 2001 From: Alex Herring Date: Sun, 22 May 2022 10:41:04 -0400 Subject: [PATCH 03/10] 204 improvements (#68) * return 204 on nil error response * allow void view actions * fix controller test for 204 nil error response * Fix `TestEmptyActionWithView` --- runtime/generator/controller/controller.gotext | 2 ++ runtime/generator/controller/controller_test.go | 10 +++++----- runtime/generator/controller/state.go | 16 ++++++++++------ 3 files changed, 17 insertions(+), 11 deletions(-) diff --git a/runtime/generator/controller/controller.gotext b/runtime/generator/controller/controller.gotext index 825de64d..05759186 100644 --- a/runtime/generator/controller/controller.gotext +++ b/runtime/generator/controller/controller.gotext @@ -118,6 +118,8 @@ func ({{$action.Short}} *{{ $.Pascal }}{{$action.Pascal}}Action) handler(httpReq {{- if $action.RespondJSON }} {{- if $action.Results.Result }} JSON: response.JSON({{ $action.Results.Result }}), + {{- else if $action.Results.IsOnlyError }} + JSON: response.Status(204), {{- else }} JSON: response.Status(200).Set("Content-Type", "application/json"), {{- end }} diff --git a/runtime/generator/controller/controller_test.go b/runtime/generator/controller/controller_test.go index 9c925bc6..82b9558b 100644 --- a/runtime/generator/controller/controller_test.go +++ b/runtime/generator/controller/controller_test.go @@ -951,15 +951,14 @@ func TestNestedResource(t *testing.T) { res, err = server.PatchJSON("/users/10", bytes.NewBufferString(`{"name": "matt", "age": 10}`)) is.NoErr(err) is.NoErr(res.Expect(` - HTTP/1.1 200 OK - Content-Type: application/json + HTTP/1.1 204 No Content + Content-Length: 0 Date: Fri, 31 Dec 2021 00:00:00 GMT `)) res, err = server.DeleteJSON("/users/10", nil) is.NoErr(err) is.NoErr(res.Expect(` - HTTP/1.1 200 OK - Content-Type: application/json + HTTP/1.1 204 No Content Date: Fri, 31 Dec 2021 00:00:00 GMT `)) } @@ -1896,11 +1895,11 @@ func TestWorkingChangeWorking(t *testing.T) { } func TestEmptyActionWithView(t *testing.T) { - t.SkipNow() is := is.New(t) ctx := context.Background() dir := t.TempDir() bud := budtest.New(dir) + bud.NodeModules["svelte"] = version.Svelte bud.Files["controller/controller.go"] = ` package controller type Controller struct {} @@ -1912,6 +1911,7 @@ func TestEmptyActionWithView(t *testing.T) { app, err := project.Build(ctx) is.NoErr(err) is.NoErr(app.Exists("bud/.app/view/view.go")) + is.NoErr(app.Exists("bud/.app/controller/controller.go")) is.NoErr(app.Exists("bud/.app/main.go")) server, err := app.Start(ctx) is.NoErr(err) diff --git a/runtime/generator/controller/state.go b/runtime/generator/controller/state.go index 158cf940..b0a6a533 100644 --- a/runtime/generator/controller/state.go +++ b/runtime/generator/controller/state.go @@ -159,14 +159,13 @@ func isList(dataType string) bool { func (results ActionResults) ViewResult() string { propsKey := results.propsKey() - if propsKey == "" { - return results.Result() - } out := new(strings.Builder) out.WriteString(`map[string]interface{}{`) - out.WriteString(strconv.Quote(propsKey)) - out.WriteString(":") - out.WriteString(results.Result()) + if propsKey != "" { + out.WriteString(strconv.Quote(propsKey)) + out.WriteString(":") + out.WriteString(results.Result()) + } out.WriteString(`},`) return out.String() } @@ -199,6 +198,11 @@ func (results ActionResults) Error() string { return "" } +// Error expression is only return +func (results ActionResults) IsOnlyError() bool { + return len(results) == 1 && results[0].IsError +} + // ActionResult struct type ActionResult struct { Name string From ee97bd4d1baceaa45feaaa612f1619985c29ea1f Mon Sep 17 00:00:00 2001 From: Matt Mueller Date: Mon, 23 May 2022 14:37:56 +0700 Subject: [PATCH 04/10] runtime/command/new/controller: Fix links when generating controllers and views (#84) runtime/command/new/controller: Fix links when generating controllers and views. Closes: #82 --- runtime/command/new/controller/controller.go | 26 ++++++++++--------- .../command/new/controller/view/index.gotext | 4 +-- .../command/new/controller/view/show.gotext | 2 +- 3 files changed, 17 insertions(+), 15 deletions(-) diff --git a/runtime/command/new/controller/controller.go b/runtime/command/new/controller/controller.go index d8576f4a..c4cc5ee7 100644 --- a/runtime/command/new/controller/controller.go +++ b/runtime/command/new/controller/controller.go @@ -80,12 +80,13 @@ type Action struct { } type View struct { - template string - Path string - Title string - Variable string - Singular string - Plural string + template string + Controller *Controller + Path string + Title string + Variable string + Singular string + Plural string } func (c *Command) Run(ctx context.Context) (err error) { @@ -160,12 +161,13 @@ func (c *Command) view(controller *Controller, action *Action) *View { template = defaultView } return &View{ - template: template, - Path: filepath.Join("view", controller.key, action.Name+".svelte"), - Title: text.Title(controller.Struct), - Variable: text.Camel(action.Result), - Singular: text.Camel(text.Singular(action.Result)), - Plural: text.Camel(text.Plural(action.Result)), + template: template, + Controller: controller, + Path: filepath.Join("view", controller.key, action.Name+".svelte"), + Title: text.Title(controller.Struct), + Variable: text.Camel(action.Result), + Singular: text.Camel(text.Singular(action.Result)), + Plural: text.Camel(text.Plural(action.Result)), } } diff --git a/runtime/command/new/controller/view/index.gotext b/runtime/command/new/controller/view/index.gotext index 69725241..1cc1cfe9 100644 --- a/runtime/command/new/controller/view/index.gotext +++ b/runtime/command/new/controller/view/index.gotext @@ -15,8 +15,8 @@ {#each {{ $.Plural }} as {{ $.Singular -}} } {#each Object.keys({{ $.Singular }}) as key} - {#if key === "id"} - { {{- $.Singular }}[key]} + {#if key.toLowerCase() === "id"} + { {{- $.Singular }}[key]} {:else} { {{- $.Singular }}[key]} {/if} diff --git a/runtime/command/new/controller/view/show.gotext b/runtime/command/new/controller/view/show.gotext index 3ddca190..32af2b3b 100644 --- a/runtime/command/new/controller/view/show.gotext +++ b/runtime/command/new/controller/view/show.gotext @@ -19,7 +19,7 @@
-Back +Back