-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathsubtask.go
121 lines (107 loc) · 3.22 KB
/
subtask.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
package ganboard
import "encoding/json"
// CreateSubtask https://docs.kanboard.org/en/latest/api/subtask_procedures.html#createsubtask
func (c *Client) CreateSubtask(params SubtaskParams) (int, error) {
query := request{
Client: c,
Method: "createSubtask",
Params: params,
}
response, err := query.decodeInt()
return response, err
}
// GetSubtask https://docs.kanboard.org/en/latest/api/subtask_procedures.html#getsubtask
func (c *Client) GetSubtask(subtaskID int) (Subtask, error) {
query := request{
Client: c,
Method: "getSubtask",
Params: map[string]int{
"subtask_id": subtaskID,
},
}
response, err := query.decodeSubtask()
return response, err
}
// GetAllSubtasks https://docs.kanboard.org/en/latest/api/subtask_procedures.html#getallsubtasks
func (c *Client) GetAllSubtasks(taskID int) ([]Subtask, error) {
query := request{
Client: c,
Method: "getAllSubtasks",
Params: map[string]int{
"task_id": taskID,
},
}
response, err := query.decodeSubtasks()
return response, err
}
// UpdateSubtask https://docs.kanboard.org/en/latest/api/subtask_procedures.html#updatesubtask
func (c *Client) UpdateSubtask(params SubtaskParams) (bool, error) {
query := request{
Client: c,
Method: "updateSubtask",
Params: params,
}
response, err := query.decodeBoolean()
return response, err
}
// RemoveSubtask https://docs.kanboard.org/en/latest/api/subtask_procedures.html#removesubtask
func (c *Client) RemoveSubtask(subtaskID int) (bool, error) {
query := request{
Client: c,
Method: "removeSubtask",
Params: map[string]int{
"subtask_id": subtaskID,
},
}
response, err := query.decodeBoolean()
return response, err
}
// SubtaskParams input for CreateSubtask
type SubtaskParams struct {
ID int `json:"id,string,omitempty"`
TaskID int `json:"task_id,string"`
Title string `json:"title"`
UserID int `json:"user_id,string,omitempty"`
TimeEstimated int `json:"time_estimated,string,omitempty"`
TimeSpent int `json:"time_spent,string,omitempty"`
Status int `json:"status,string,omitempty"`
}
// Subtask type
type Subtask struct {
ID int `json:"id,string"`
TaskID int `json:"task_id,string"`
Title string `json:"title"`
UserID int `json:"user_id,string,omitempty"`
Username string `json:"username"`
Name string `json:"name"`
StatusName string `json:"status_name"`
TimeEstimated int `json:"time_estimated,string,omitempty"`
TimeSpent int `json:"time_spent,string,omitempty"`
Status int `json:"status,string,omitempty"`
}
func (r *request) decodeSubtasks() ([]Subtask, error) {
rsp, err := r.Client.Request(*r)
if err != nil {
return nil, err
}
body := struct {
JSONRPC string `json:"jsonrpc"`
ID FlexInt `json:"id"`
Result []Subtask `json:"result"`
}{}
err = json.NewDecoder(rsp.Body).Decode(&body)
return body.Result, err
}
func (r *request) decodeSubtask() (Subtask, error) {
rsp, err := r.Client.Request(*r)
if err != nil {
return Subtask{}, err
}
body := struct {
JSONRPC string `json:"jsonrpc"`
ID FlexInt `json:"id"`
Result Subtask `json:"result"`
}{}
err = json.NewDecoder(rsp.Body).Decode(&body)
return body.Result, err
}