-
Notifications
You must be signed in to change notification settings - Fork 0
/
card-types.go
58 lines (46 loc) · 1.1 KB
/
card-types.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
package nrdb
import (
"fmt"
"net/url"
"time"
)
type CardType struct {
Document[CardTypeAttributes, CardTypeRelationships]
}
type CardTypeAttributes struct {
Name string `json:"name"`
SideID string `json:"side_id"`
UpdatedAt time.Time `json:"updated_at"`
}
type CardTypeRelationships struct {
Cards *Relationship `json:"cards"`
Side *Relationship `json:"side"`
}
type CardTypeFilter struct {
SideID string
}
func (filter CardTypeFilter) Encode() (url.Values, error) {
query := url.Values{}
if filter.SideID != "" {
query.Set("filter[side_id]", filter.SideID)
}
return query, nil
}
func (doc CardType) String() string {
return fmt.Sprintf("%s - %s (%s)", doc.Attributes.Name, doc.Attributes.SideID, doc.ID)
}
func (cl client) CardTypes(filter *CardTypeFilter) ([]*CardType, error) {
var res Response[[]*CardType]
var query url.Values
if filter != nil {
q, err := filter.Encode()
if err != nil {
return nil, fmt.Errorf("encoding filter: %w", err)
}
query = q
}
if err := cl.nrdbReq("card_types", &res, query); err != nil {
return nil, err
}
return res.Data, nil
}