forked from Mirrors/jsonapi
dry off
This commit is contained in:
parent
84eed2060a
commit
97cf7cfca4
19
response.go
19
response.go
|
@ -154,11 +154,7 @@ func visitModelNode(model interface{}, sideload bool) (*JsonApiNode, []*JsonApiN
|
|||
shallowNodes := make([]*JsonApiNode, 0)
|
||||
for _, node := range d {
|
||||
included = append(included, node)
|
||||
|
||||
shallowNode := *node
|
||||
shallowNode.Attributes = nil
|
||||
shallowNodes = append(shallowNodes, &shallowNode)
|
||||
|
||||
shallowNodes = append(shallowNodes, cloneAndRemoveAttributes(node))
|
||||
}
|
||||
|
||||
node.Relationships[args[1]] = &JsonApiRelationshipManyNode{Data: shallowNodes}
|
||||
|
@ -173,12 +169,8 @@ func visitModelNode(model interface{}, sideload bool) (*JsonApiNode, []*JsonApiN
|
|||
relationship, _, err := visitModelNode(fieldValue.Interface(), sideload)
|
||||
if err == nil {
|
||||
if sideload {
|
||||
shallowNode := *relationship
|
||||
shallowNode.Attributes = nil
|
||||
|
||||
included = append(included, relationship)
|
||||
|
||||
node.Relationships[args[1]] = &JsonApiRelationshipOneNode{Data: &shallowNode}
|
||||
node.Relationships[args[1]] = &JsonApiRelationshipOneNode{Data: cloneAndRemoveAttributes(relationship)}
|
||||
} else {
|
||||
node.Relationships[args[1]] = &JsonApiRelationshipOneNode{Data: relationship}
|
||||
}
|
||||
|
@ -204,6 +196,13 @@ func visitModelNode(model interface{}, sideload bool) (*JsonApiNode, []*JsonApiN
|
|||
return node, included, nil
|
||||
}
|
||||
|
||||
func cloneAndRemoveAttributes(node *JsonApiNode) *JsonApiNode {
|
||||
n := *node
|
||||
n.Attributes = nil
|
||||
|
||||
return &n
|
||||
}
|
||||
|
||||
func visitModelNodeRelationships(relationName string, models reflect.Value, sideload bool) (map[string]*JsonApiRelationshipManyNode, error) {
|
||||
m := make(map[string]*JsonApiRelationshipManyNode)
|
||||
nodes := make([]*JsonApiNode, 0)
|
||||
|
|
Loading…
Reference in New Issue