Skip to content

Commit

Permalink
Merge pull request #78 from sev-2/feature/return-representation-on-write
Browse files Browse the repository at this point in the history
FEAT Always return representation after write operation
  • Loading branch information
toopay authored Oct 8, 2024
2 parents 5b7c67c + fb13e4b commit 1516ea6
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 4 deletions.
9 changes: 9 additions & 0 deletions controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand All @@ -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)
}

Expand All @@ -347,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)
}

Expand Down
6 changes: 3 additions & 3 deletions pkg/db/relation.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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)
Expand Down Expand Up @@ -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.")
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/db/select.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 1516ea6

Please sign in to comment.