-
Notifications
You must be signed in to change notification settings - Fork 4
/
swimlane.go
212 lines (190 loc) · 5.52 KB
/
swimlane.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
package ganboard
import "encoding/json"
// GetActiveSwimlanes https://docs.kanboard.org/en/latest/api/swimlane_procedures.html#swimlane-api-procedures
func (c *Client) GetActiveSwimlanes(projectID int) ([]Swimlane, error) {
query := request{
Client: c,
Method: "getActiveSwimlanes",
Params: map[string]int{
"project_id": projectID,
},
}
response, err := query.decodeSwimlanes()
return response, err
}
// GetAllSwimlanes https://docs.kanboard.org/en/latest/api/swimlane_procedures.html#getallswimlanes
func (c *Client) GetAllSwimlanes(projectID int) ([]Swimlane, error) {
query := request{
Client: c,
Method: "getAllSwimlanes",
Params: map[string]int{
"project_id": projectID,
},
}
response, err := query.decodeSwimlanes()
return response, err
}
// GetSwimlane https://docs.kanboard.org/en/latest/api/swimlane_procedures.html#getswimlane
func (c *Client) GetSwimlane(swimlaneID int) (Swimlane, error) {
query := request{
Client: c,
Method: "getSwimlane",
Params: map[string]int{
"swimlane_id": swimlaneID,
},
}
response, err := query.decodeSwimlane()
return response, err
}
// GetSwimlaneByID https://docs.kanboard.org/en/latest/api/swimlane_procedures.html#getswimlanebyid
func (c *Client) GetSwimlaneByID(swimlaneID int) (Swimlane, error) {
query := request{
Client: c,
Method: "getSwimlaneById",
Params: map[string]int{
"swimlane_id": swimlaneID,
},
}
response, err := query.decodeSwimlane()
return response, err
}
// GetSwimlaneByName https://docs.kanboard.org/en/latest/api/swimlane_procedures.html#getswimlanebyname
func (c *Client) GetSwimlaneByName(projectID int, name string) (Swimlane, error) {
query := request{
Client: c,
Method: "getSwimlaneByName",
Params: struct {
ProjectID int `json:"project_id"`
Name string `json:"Name"`
}{
ProjectID: projectID,
Name: name,
},
}
response, err := query.decodeSwimlane()
return response, err
}
// ChangeSwimlanePosition https://docs.kanboard.org/en/latest/api/swimlane_procedures.html#changeswimlaneposition
func (c *Client) ChangeSwimlanePosition(projectID int, swimlaneID int, position int) (bool, error) {
query := request{
Client: c,
Method: "getSwimlaneByName",
Params: map[string]int{
"project_id": projectID,
"swimlane_id": swimlaneID,
"position": position,
},
}
response, err := query.decodeBoolean()
return response, err
}
// UpdateSwimlane https://docs.kanboard.org/en/latest/api/swimlane_procedures.html#updateswimlane
func (c *Client) UpdateSwimlane(params SwimlaneParams) (bool, error) {
query := request{
Client: c,
Method: "getSwimlaneByName",
Params: params,
}
response, err := query.decodeBoolean()
return response, err
}
// AddSwimlane https://docs.kanboard.org/en/latest/api/swimlane_procedures.html#addswimlane
func (c *Client) AddSwimlane(params SwimlaneParams) (int, error) {
query := request{
Client: c,
Method: "AddSwimlane",
Params: params,
}
response, err := query.decodeInt()
return response, err
}
// RemoveSwimlane https://docs.kanboard.org/en/latest/api/swimlane_procedures.html#removeswimlane
func (c *Client) RemoveSwimlane(projectID int, swimlaneID int) (bool, error) {
query := request{
Client: c,
Method: "RemoveSwimlane",
Params: map[string]int{
"project_id": projectID,
"swimlane_id": swimlaneID,
},
}
response, err := query.decodeBoolean()
return response, err
}
// DisableSwimlane https://docs.kanboard.org/en/latest/api/swimlane_procedures.html#disableswimlane
func (c *Client) DisableSwimlane(projectID int, swimlaneID int) (bool, error) {
query := request{
Client: c,
Method: "DisableSwimlane",
Params: map[string]int{
"project_id": projectID,
"swimlane_id": swimlaneID,
},
}
response, err := query.decodeBoolean()
return response, err
}
// EnableSwimlane https://docs.kanboard.org/en/latest/api/swimlane_procedures.html#enableswimlane
func (c *Client) EnableSwimlane(projectID int, swimlaneID int) (bool, error) {
query := request{
Client: c,
Method: "EnableSwimlane",
Params: map[string]int{
"project_id": projectID,
"swimlane_id": swimlaneID,
},
}
response, err := query.decodeBoolean()
return response, err
}
// Swimlane type
type Swimlane struct {
ID int `json:"id"`
Name string `json:"name"`
Position int `json:"position,string"`
IsActive int `json:"is_active,string"`
ProjectID int `json:"project_id,string"`
}
// SwimlaneParams input
type SwimlaneParams struct {
Description string `json:"description,omitempty"`
Name string `json:"name"`
ProjectID int `json:"project_id,string"`
SwimlaneID int `json:"swimlane_id,string,omitempty"`
}
type responseSwimlanes struct {
JSONRPC string `json:"jsonrpc"`
ID int `json:"id"`
Result []Swimlane `json:"result"`
}
type responseSwimlane struct {
JSONRPC string `json:"jsonrpc"`
ID int `json:"id"`
Result Swimlane `json:"result"`
}
func (r *request) decodeSwimlanes() ([]Swimlane, error) {
rsp, err := r.Client.Request(*r)
if err != nil {
return nil, err
}
body := struct {
JSONRPC string `json:"jsonrpc"`
ID FlexInt `json:"id"`
Result []Swimlane `json:"result"`
}{}
err = json.NewDecoder(rsp.Body).Decode(&body)
return body.Result, err
}
func (r *request) decodeSwimlane() (Swimlane, error) {
rsp, err := r.Client.Request(*r)
if err != nil {
return Swimlane{}, err
}
body := struct {
JSONRPC string `json:"jsonrpc"`
ID FlexInt `json:"id"`
Result Swimlane `json:"result"`
}{}
err = json.NewDecoder(rsp.Body).Decode(&body)
return body.Result, err
}