From 29bbaca37c556a4afbe6b54bf4463ed89aad0fc7 Mon Sep 17 00:00:00 2001 From: Taufan Adhitya Date: Tue, 8 Oct 2024 10:38:58 +0700 Subject: [PATCH 1/3] feat: always return representation after write operation --- controller.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/controller.go b/controller.go index 8dabedd9..b747f547 100644 --- a/controller.go +++ b/controller.go @@ -309,6 +309,9 @@ func (rc RestController) Patch(ctx Context) error { return err1 } + // Set prefer representation header as default + ctx.RequestContext().Request.Header.Add("Prefer", "return=representation") + return RestProxy(ctx, rc.TableName) } @@ -332,6 +335,9 @@ func (rc RestController) Post(ctx Context) error { return err1 } + // Set prefer representation header as default + ctx.RequestContext().Request.Header.Add("Prefer", "return=representation") + return RestProxy(ctx, rc.TableName) } From a824f2ea94923118aa822d5fd358ec2a01a098e9 Mon Sep 17 00:00:00 2001 From: Taufan Adhitya Date: Tue, 8 Oct 2024 11:20:53 +0700 Subject: [PATCH 2/3] feat: de-escalate fatal into panic for DB ops --- pkg/db/relation.go | 6 +++--- pkg/db/select.go | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/pkg/db/relation.go b/pkg/db/relation.go index 04666b23..ac3fd6b6 100644 --- a/pkg/db/relation.go +++ b/pkg/db/relation.go @@ -32,7 +32,7 @@ func (q *Query) Preload(table string, args ...string) *Query { relations := strings.Split(table, ".") if len(relations) > 3 { - raiden.Fatal("unsupported nested relations more than 3 levels") + raiden.Panic("unsupported nested relations more than 3 levels") } for i, relation := range relations { @@ -48,7 +48,7 @@ func (q *Query) Preload(table string, args ...string) *Query { } if err != nil { - raiden.Fatal("could not find related model.") + raiden.Panic("could not find related model.") } relatedModelStruct := reflect.TypeOf(relatedModel) @@ -80,7 +80,7 @@ func (q *Query) Preload(table string, args ...string) *Query { relatedForeignKey, err = getTagValue(join, "foreignKey") if err != nil { - raiden.Fatal("could not find foreign key in join tag.") + raiden.Panic("could not find foreign key in join tag.") } } } diff --git a/pkg/db/select.go b/pkg/db/select.go index edb255ab..7bc7af6e 100644 --- a/pkg/db/select.go +++ b/pkg/db/select.go @@ -23,7 +23,7 @@ func (q Query) Select(columns []string) (model *Query) { column = split[1] if !isValidColumnName(alias) { err := fmt.Sprintf("invalid alias column name: \"%s\" name is invalid.", alias) - raiden.Fatal(err) + raiden.Panic(err) } } else { column = c From fb13e4b5ab4f6277cc76bcf9f4051748c0dc2cd4 Mon Sep 17 00:00:00 2001 From: Taufan Adhitya Date: Tue, 8 Oct 2024 11:22:18 +0700 Subject: [PATCH 3/3] feat: always return representation after write operation --- controller.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/controller.go b/controller.go index b747f547..0586bc62 100644 --- a/controller.go +++ b/controller.go @@ -353,6 +353,9 @@ func (rc RestController) Put(ctx Context) error { return err1 } + // Set prefer representation header as default + ctx.RequestContext().Request.Header.Add("Prefer", "return=representation") + return RestProxy(ctx, rc.TableName) }