-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy patheventapi_results.go
70 lines (60 loc) · 1.44 KB
/
eventapi_results.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
69
70
package webapi
import (
"encoding/json"
model "github.com/raceresult/go-model"
)
// Results contains all api endpoints regarding results
type Results struct {
api *EventAPI
}
// newResults creates a new Results api endpoint group
func newResults(api *EventAPI) *Results {
return &Results{
api: api,
}
}
// Get returns results matching the given filters
func (q *Results) Get(name string, onlyFormulas, onlyNoFormulas bool) ([]model.Result, error) {
values := urlValues{
"name": name,
"onlyFormulas": onlyFormulas,
"onlyNoFormulas": onlyNoFormulas,
}
bts, err := q.api.get("results/get", values)
if err != nil {
return nil, err
}
var dest []model.Result
if err := json.Unmarshal(bts, &dest); err != nil {
return nil, err
}
return dest, nil
}
// GetOne returns results with the given ID
func (q *Results) GetOne(id int) (*model.Result, error) {
values := urlValues{
"id": id,
}
bts, err := q.api.get("results/get", values)
if err != nil {
return nil, err
}
var dest model.Result
if err := json.Unmarshal(bts, &dest); err != nil {
return nil, err
}
return &dest, nil
}
// Delete deletes results
func (q *Results) Delete(id int) error {
values := urlValues{
"id": id,
}
_, err := q.api.get("results/delete", values)
return err
}
// Save saves results and returns the result IDs
func (q *Results) Save(items []model.Result) error { // TODO: oldID
_, err := q.api.post("results/save", nil, items)
return err
}