-
Notifications
You must be signed in to change notification settings - Fork 4
/
column.go
119 lines (105 loc) · 2.9 KB
/
column.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
package ganboard
import "encoding/json"
// GetColumns https://docs.kanboard.org/en/latest/api/column_procedures.html#getcolumns
func (c *Client) GetColumns(projectID int) ([]Column, error) {
query := request{
Client: c,
Method: "getColumns",
Params: map[string]int{
"project_id": projectID,
},
}
response, err := query.decodeColumns()
return response, err
}
// GetColumn https://docs.kanboard.org/en/latest/api/column_procedures.html#getcolumn
func (c *Client) GetColumn(columnID int) (Column, error) {
query := request{
Client: c,
Method: "getColumn",
Params: map[string]int{
"column_id": columnID,
},
}
response, err := query.decodeColumn()
return response, err
}
// ChangeColumnPosition https://docs.kanboard.org/en/latest/api/column_procedures.html#changecolumnposition
func (c *Client) ChangeColumnPosition(projectID int, columnID int, position int) (bool, error) {
query := request{
Client: c,
Method: "changeColumnPosition",
Params: map[string]int{
"project_id": projectID,
"column_id": columnID,
"position": position,
},
}
response, err := query.decodeBoolean()
return response, err
}
// UpdateColumn https://docs.kanboard.org/en/latest/api/column_procedures.html#updatecolumn
func (c *Client) UpdateColumn(params ColumnParams) (bool, error) {
query := request{
Client: c,
Method: "updateColumn",
Params: params,
}
response, err := query.decodeBoolean()
return response, err
}
// AddColumn https://docs.kanboard.org/en/latest/api/column_procedures.html#addcolumn
func (c *Client) AddColumn(params ColumnParams) (int, error) {
query := request{
Client: c,
Method: "addColumn",
Params: params,
}
response, err := query.decodeInt()
return response, err
}
// RemoveColumn https://docs.kanboard.org/en/latest/api/column_procedures.html#removecolumn
func (c *Client) RemoveColumn(columnID int) (bool, error) {
query := request{
Client: c,
Method: "addColumn",
Params: map[string]int{
"column_id": columnID,
},
}
response, err := query.decodeBoolean()
return response, err
}
// ColumnParams input for UpdateColumn
type ColumnParams struct {
ColumnID int `json:"column_id"`
Title string `json:"title"`
TaskLimit int `json:"task_limit,omitempty"`
Description string `json:"description,omitempty"`
}
func (r *request) decodeColumn() (Column, error) {
rsp, err := r.Client.Request(*r)
if err != nil {
return Column{}, err
}
body := struct {
JSONRPC string `json:"jsonrpc"`
ID int `json:"id"`
Result Column `json:"result"`
}{}
err = json.NewDecoder(rsp.Body).Decode(&body)
return body.Result, err
}
func (r *request) decodeColumns() ([]Column, error) {
rsp, err := r.Client.Request(*r)
if err != nil {
return nil, err
}
body := struct {
JSONRPC string `json:"jsonrpc"`
ID int `json:"id"`
Result []Column `json:"result"`
}{}
err = json.NewDecoder(rsp.Body).Decode(&body)
return body.Result, err
}