Skip to content

Commit de7cbe8

Browse files
author
Matt Collum
authored
Merge pull request #1 from EveryFinancial/add-include-filtering
make included list available for filtering. not pretty but works for…
2 parents 3b9f84a + 069efa2 commit de7cbe8

File tree

1 file changed

+24
-2
lines changed

1 file changed

+24
-2
lines changed

node.go

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ import "fmt"
55
// Payloader is used to encapsulate the One and Many payload types
66
type Payloader interface {
77
clearIncluded()
8+
GetIncluded() []*Node
9+
SetIncluded([]*Node)
810
}
911

1012
// OnePayload is used to represent a generic JSON API payload where a single
@@ -20,6 +22,16 @@ func (p *OnePayload) clearIncluded() {
2022
p.Included = []*Node{}
2123
}
2224

25+
//GetIncluded returns current included items
26+
func (p *OnePayload) GetIncluded() []*Node {
27+
return p.Included
28+
}
29+
30+
//SetIncluded updates included
31+
func (p *OnePayload) SetIncluded(newIncluded []*Node) {
32+
p.Included = newIncluded
33+
}
34+
2335
// ManyPayload is used to represent a generic JSON API payload where many
2436
// resources (Nodes) were included in an [] in the "data" key
2537
type ManyPayload struct {
@@ -33,6 +45,16 @@ func (p *ManyPayload) clearIncluded() {
3345
p.Included = []*Node{}
3446
}
3547

48+
//SetIncluded updates included
49+
func (p *ManyPayload) SetIncluded(newIncluded []*Node) {
50+
p.Included = newIncluded
51+
}
52+
53+
//GetIncluded returns current included items
54+
func (p *ManyPayload) GetIncluded() []*Node {
55+
return p.Included
56+
}
57+
3658
// Node is used to represent a generic JSON API Resource
3759
type Node struct {
3860
Type string `json:"type"`
@@ -46,15 +68,15 @@ type Node struct {
4668

4769
// RelationshipOneNode is used to represent a generic has one JSON API relation
4870
type RelationshipOneNode struct {
49-
Data *Node `json:"data"`
71+
Data *Node `json:"data,omitempty"`
5072
Links *Links `json:"links,omitempty"`
5173
Meta *Meta `json:"meta,omitempty"`
5274
}
5375

5476
// RelationshipManyNode is used to represent a generic has many JSON API
5577
// relation
5678
type RelationshipManyNode struct {
57-
Data []*Node `json:"data"`
79+
Data []*Node `json:"data,omitempty"`
5880
Links *Links `json:"links,omitempty"`
5981
Meta *Meta `json:"meta,omitempty"`
6082
}

0 commit comments

Comments
 (0)