-
Notifications
You must be signed in to change notification settings - Fork 3
/
eventapi_customfields.go
68 lines (58 loc) · 1.42 KB
/
eventapi_customfields.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
59
60
61
62
63
64
65
66
67
68
package webapi
import (
"encoding/json"
model "github.com/raceresult/go-model"
)
// CustomFields contains all api endpoints regarding custom fields
type CustomFields struct {
api *EventAPI
}
// newCustomFields creates a new CustomFields api endpoint group
func newCustomFields(api *EventAPI) *CustomFields {
return &CustomFields{
api: api,
}
}
// Get returns custom fields matching the given filters
func (q *CustomFields) Get() ([]model.CustomField, error) {
bts, err := q.api.get("fields/get", nil)
if err != nil {
return nil, err
}
var dest []model.CustomField
if err := json.Unmarshal(bts, &dest); err != nil {
return nil, err
}
return dest, nil
}
// GetOne returns the custom field with the given ID
func (q *CustomFields) GetOne(id int) (*model.CustomField, error) {
values := urlValues{
"id": id,
}
bts, err := q.api.get("fields/get", values)
if err != nil {
return nil, err
}
var dest model.CustomField
if err := json.Unmarshal(bts, &dest); err != nil {
return nil, err
}
return &dest, nil
}
// Delete deletes a custom field
func (q *CustomFields) Delete(id int) error {
values := urlValues{
"id": id,
}
_, err := q.api.get("fields/delete", values)
return err
}
// Save saves custom fields and returns the IDs
func (q *CustomFields) Save(items []model.CustomField) ([]int, error) {
bts, err := q.api.post("fields/save", nil, items)
if err != nil {
return nil, err
}
return parseJsonIntArr(bts)
}