-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy patheventapi_times.go
167 lines (147 loc) · 3.98 KB
/
eventapi_times.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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
package webapi
import (
"encoding/json"
model "github.com/raceresult/go-model"
"github.com/raceresult/go-model/decimal"
)
// Times contains all api endpoints regarding times
type Times struct {
api *EventAPI
}
// newTimes creates a new Times api endpoint group
func newTimes(api *EventAPI) *Times {
return &Times{
api: api,
}
}
// ExcelExport returns times matching the given filters as csv file
func (q *Times) ExcelExport(bib int, result int, lang string) ([]byte, error) {
values := urlValues{
"bib": bib,
"result": result,
"lang": lang,
}
return q.api.get("times/excelexport", values)
}
// Delete deletes times matching the given filters
func (q *Times) Delete(bib, contest, result int, filter string, filterInfo string) error {
values := urlValues{
"bib": bib,
"contest": contest,
"result": result,
"filter": filter,
"filterInfo": filterInfo,
}
_, err := q.api.get("times/delete", values)
return err
}
// Swap swaps the times of two participants
func (q *Times) Swap(bib1, bib2 int) error {
values := urlValues{
"bib1": bib1,
"bib2": bib2,
}
_, err := q.api.get("times/swap", values)
return err
}
// SingleStart creates single start times
func (q *Times) SingleStart(result int, contest int, firstTime decimal.Decimal, interval decimal.Decimal, sort string,
filter string, noHistory bool) error {
values := urlValues{
"result": result,
"contest": contest,
"firstTime": firstTime,
"interval": interval,
"sort": sort,
"filter": filter,
"noHistory": noHistory,
}
_, err := q.api.get("times/singlestart", values)
return err
}
// RandomTimes creates random times
func (q *Times) RandomTimes(result int, contest int, minTime decimal.Decimal, maxTime decimal.Decimal, offsetResult int,
filter string, noHistory bool) error {
values := urlValues{
"result": result,
"contest": contest,
"minTime": minTime,
"maxTime": maxTime,
"offsetResult": offsetResult,
"filter": filter,
"noHistory": noHistory,
}
_, err := q.api.get("times/randomtimes", values)
return err
}
// Copy copies times from one participant to another
func (q *Times) Copy(bibFrom, bibTo int, overwriteExisting bool) error {
values := urlValues{
"bibFrom": bibFrom,
"bibTo": bibTo,
"overwriteExisting": overwriteExisting,
}
_, err := q.api.get("times/copy", values)
return err
}
// Interpolate interpolates missing times
func (q *Times) Interpolate(destID, helperID int, contest int, helpers int) error {
values := urlValues{
"destID": destID,
"helperID": helperID,
"contest": contest,
"helpers": helpers,
}
_, err := q.api.get("times/interpolate", values)
return err
}
// Get returns times matching the given filters
func (q *Times) Get(bib int, result int) ([]model.Time, error) {
values := urlValues{
"bib": bib,
"result": result,
}
bts, err := q.api.get("times/get", values)
if err != nil {
return nil, err
}
var dest []model.Time
if err := json.Unmarshal(bts, &dest); err != nil {
return nil, err
}
return dest, nil
}
// Count counts times matching the given filters
func (q *Times) Count(bib int, contest int, result int, filter string) (int, error) {
values := urlValues{
"bib": bib,
"contest": contest,
"result": result,
"filter": filter,
}
bts, err := q.api.get("times/count", values)
if err != nil {
return 0, err
}
var count int
err = json.Unmarshal(bts, &count)
return count, err
}
// Add adds times/passings
func (q *Times) Add(passings []model.Passing, returnFields []string, contestFilter int, ignoreBibToBibAssign bool) (
[]model.TimesAddResponseItem, error) {
values := urlValues{
"returnFields": returnFields,
"contestFilter": contestFilter,
"ignoreBibToBibAssign": ignoreBibToBibAssign,
}
bts, err := q.api.post("times/add", values, passings)
if err != nil {
return nil, err
}
var dest []model.TimesAddResponseItem
if err := json.Unmarshal(bts, &dest); err != nil {
return nil, err
}
return dest, nil
}