-
Notifications
You must be signed in to change notification settings - Fork 4
/
task.go
303 lines (279 loc) · 9.62 KB
/
task.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
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
package ganboard
import (
"encoding/json"
"time"
)
// CreateTask https://docs.kanboard.org/en/latest/api/task_procedures.html#createtask
func (c *Client) CreateTask(params TaskParams) (int, error) {
query := request{
Client: c,
Method: "createTask",
Params: params,
}
response, err := query.decodeInt()
return response, err
}
// GetTask https://docs.kanboard.org/en/latest/api/task_procedures.html#gettask
func (c *Client) GetTask(taskID int) (Task, error) {
query := request{
Client: c,
Method: "getTask",
Params: map[string]int{
"task_id": taskID,
},
}
response, err := query.decodeTask()
return response, err
}
// GetTaskByReference https://docs.kanboard.org/en/latest/api/task_procedures.html#gettaskbyreference
func (c *Client) GetTaskByReference(taskID int, reference string) (Task, error) {
query := request{
Client: c,
Method: "getTaskByReference",
Params: struct {
TaskID int `json:"task_id"`
Reference string `json:"reference"`
}{
TaskID: taskID,
Reference: reference,
},
}
response, err := query.decodeTask()
return response, err
}
// GetAllTasks https://docs.kanboard.org/en/latest/api/task_procedures.html#getalltasks
func (c *Client) GetAllTasks(projectID int, statusID int) ([]Task, error) {
query := request{
Client: c,
Method: "getAllTasks",
Params: map[string]int{
"project_id": projectID,
"status_id": statusID,
},
}
response, err := query.decodeTasks()
return response, err
}
// GetOverdueTasks https://docs.kanboard.org/en/latest/api/task_procedures.html#getoverduetasks
func (c *Client) GetOverdueTasks() ([]Task, error) {
query := request{
Client: c,
Method: "getOverdueTasks",
}
response, err := query.decodeTasks()
return response, err
}
// GetOverdueTasksByProject https://docs.kanboard.org/en/latest/api/task_procedures.html#getoverduetasksbyproject
func (c *Client) GetOverdueTasksByProject(projectID int) ([]Task, error) {
query := request{
Client: c,
Method: "getOverdueTasksByProject",
Params: map[string]int{
"project_id": projectID,
},
}
response, err := query.decodeTasks()
return response, err
}
// UpdateTask https://docs.kanboard.org/en/latest/api/task_procedures.html#updatetask
func (c *Client) UpdateTask(params TaskParams) (bool, error) {
query := request{
Client: c,
Method: "updateTask",
Params: params,
}
response, err := query.decodeBoolean()
return response, err
}
// OpenTask https://docs.kanboard.org/en/latest/api/task_procedures.html#opentask
func (c *Client) OpenTask(taskID int) (bool, error) {
query := request{
Client: c,
Method: "openTask",
Params: map[string]int{
"task_id": taskID,
},
}
response, err := query.decodeBoolean()
return response, err
}
// CloseTask https://docs.kanboard.org/en/latest/api/task_procedures.html#closetask
func (c *Client) CloseTask(taskID int) (bool, error) {
query := request{
Client: c,
Method: "closeTask",
Params: map[string]int{
"task_id": taskID,
},
}
response, err := query.decodeBoolean()
return response, err
}
// RemoveTask https://docs.kanboard.org/en/latest/api/task_procedures.html#removetask
func (c *Client) RemoveTask(taskID int) (bool, error) {
query := request{
Client: c,
Method: "removeTask",
Params: map[string]int{
"task_id": taskID,
},
}
response, err := query.decodeBoolean()
return response, err
}
// MoveTaskPosition https://docs.kanboard.org/en/latest/api/task_procedures.html#movetaskposition
func (c *Client) MoveTaskPosition(projectID int, taskID int, columnID int, position int, swimlaneID int) (bool, error) {
query := request{
Client: c,
Method: "moveTaskPosition",
Params: map[string]int{
"project_id": projectID,
"task_id": taskID,
"column_id": columnID,
"position": position,
"swimlane_id": swimlaneID,
},
}
response, err := query.decodeBoolean()
return response, err
}
// MoveTaskToProject https://docs.kanboard.org/en/latest/api/task_procedures.html#movetasktoproject
func (c *Client) MoveTaskToProject(params MoveTaskParams) (bool, error) {
query := request{
Client: c,
Method: "moveTaskToProject",
Params: params,
}
response, err := query.decodeBoolean()
return response, err
}
// DuplicateTaskToProject https://docs.kanboard.org/en/latest/api/task_procedures.html#duplicatetasktoproject
func (c *Client) DuplicateTaskToProject(params MoveTaskParams) (bool, error) {
query := request{
Client: c,
Method: "duplicateTaskToProject",
Params: params,
}
response, err := query.decodeBoolean()
return response, err
}
// SearchTasks https://docs.kanboard.org/en/latest/api/task_procedures.html#searchtasks
func (c *Client) SearchTasks(projectID int, queryString string) ([]Task, error) {
query := request{
Client: c,
Method: "searchTasks",
Params: struct {
ProjectID int `json:"project_id,string"`
Query string `json:"query"`
}{
ProjectID: projectID,
Query: queryString,
},
}
response, err := query.decodeTasks()
return response, err
}
// TaskParams input for CreateTask
type TaskParams struct {
ID int `json:"id,omitempty"`
Title string `json:"title"`
ProjectID int `json:"project_id"`
ColorID string `json:"color_id,omitempty"`
ColumnID int `json:"column_id,string,omitempty"`
OwnerID int `json:"owner_id,string,omitempty"`
CreatorID int `json:"creator_id,omitempty"`
DateDue *time.Time `json:"date_due,omitempty"`
Description string `json:"description,omitempty"`
CategoryID int `json:"category_id,string,omitempty"`
Score int `json:"score,string,omitempty"`
SwimlaneID int `json:"swimlane_id,string,omitempty"`
Priority int `json:"priority,omitempty"`
RecurrenceStatus int `json:"recurrence_status,string,omitempty"`
RecurrenceTrigger int `json:"recurrence_trigger,string,omitempty"`
RecurrenceFactor int `json:"recurrence_factor,string,omitempty"`
RecurrenceTimeframe int `json:"recurrence_timeframe,string,omitempty"`
RecurrenceBaseDate int `json:"recurrence_basedate,string,omitempty"`
Tags []string `json:"tags,omitempty"`
DateStarted *time.Time `json:"date_started,omitempty"`
}
// MoveTaskParams input for MoveTaskToProject
type MoveTaskParams struct {
TaskID int `json:"task_id,string"`
ProjectID int `json:"project_id,string"`
SwimlaneID int `json:"swimlane_id,string,omitempty"`
ColumnID int `json:"column_id,string,omitempty"`
CategoryID int `json:"category_id,string,omitempty"`
OwnerID int `json:"owner_id,string,omitempty"`
}
// Task type
type Task struct {
ID int `json:"id,string,omitempty"`
ProjectID int `json:"project_id,string"`
ColorID string `json:"color_id,omitempty"`
ColumnID int `json:"column_id,string,omitempty"`
OwnerID int `json:"owner_id,string,omitempty"`
CreatorID int `json:"creator_id,omitempty"`
DateDue int `json:"date_due,string,omitempty"`
Reference string `json:"reference"`
Title string `json:"title"`
Description string `json:"description"`
DateCreation int `json:"date_creation,string"`
DateCompleted int `json:"date_completed,string"`
DateModification int `json:"date_modification,string"`
DateStarted int `json:"date_started,string"`
TimeEstimated int `json:"time_estimated,string"`
TimeSpent int `json:"time_spend,string"`
Position int `json:"position,string"`
IsActive int `json:"is_active,string"`
Score int `json:"score,string"`
CategoryID int `json:"category_id,string"`
SwimlaneID int `json:"swimlane_id,string,omitempty"`
DateMoved int `json:"date_moved"`
RecurrenceStatus int `json:"recurrence_status,string"`
RecurrenceTrigger int `json:"recurrence_trigger,string"`
RecurrenceFactor int `json:"recurrence_factor,string"`
RecurrenceTimeframe int `json:"recurrence_timeframe,string"`
RecurrenceBaseDate int `json:"recurrence_basedate,string"`
RecurrenceParent int `json:"recurrence_parent,string"`
RecurrenceChild int `json:"recurrence_child,string"`
CategoryName string `json:"category_name"`
ProjectName string `json:"project_name"`
DefaultSwimlane string `json:"default_swimlane"`
ColumnTitle string `json:"column_title"`
AssigneeUsername string `json:"assignee_username"`
AssigneeName string `json:"assignee_name"`
CreatorUsername string `json:"creator_username"`
CreatorName string `json:"creator_name"`
NbComments int `json:"nb_comments,string"`
NbFiles int `json:"nb_files,string"`
NbSubtasks int `json:"nb_subtasks,string"`
NbCompletedSubtasks int `json:"nb_completed_subtasks,string"`
NbLinks int `json:"nb_links,string"`
Color Color `json:"color"`
}
func (r *request) decodeTasks() ([]Task, error) {
rsp, err := r.Client.Request(*r)
if err != nil {
return nil, err
}
body := struct {
JSONRPC string `json:"jsonrpc"`
ID FlexInt `json:"id"`
Result []Task `json:"result"`
}{}
err = json.NewDecoder(rsp.Body).Decode(&body)
return body.Result, err
}
func (r *request) decodeTask() (Task, error) {
rsp, err := r.Client.Request(*r)
if err != nil {
return Task{}, err
}
body := struct {
JSONRPC string `json:"jsonrpc"`
ID FlexInt `json:"id"`
Result Task `json:"result"`
}{}
err = json.NewDecoder(rsp.Body).Decode(&body)
return body.Result, err
}