forked from desertbit/wego
-
Notifications
You must be signed in to change notification settings - Fork 0
/
client_boards.go
319 lines (264 loc) · 9.29 KB
/
client_boards.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
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
/**
* Copyright (c) 2023 Sebastian Borchers
*
* This software is released under the MIT License.
* https://opensource.org/licenses/MIT
*/
package wego
import (
"context"
"encoding/json"
"time"
)
// GetPublicBoards performs a get_public_boards request against the Wekan server.
// See https://wekan.github.io/api/v5.13/#get_public_boards
func (c *Client) GetPublicBoards(ctx context.Context) (boards []GetPublicBoard, err error) {
const endpoint = "/api/boards"
req, err := c.newAuthenticatedGETRequest(ctx, endpoint)
if err != nil {
return
}
err = c.doSimpleRequest(req, &boards)
if err != nil {
return
}
return
}
// NewBoard performs a new_board request against the Wekan server.
// See https://wekan.github.io/api/v5.13/#new_board
//
// Note: Owner must be a userID, not an email or username.
func (c *Client) NewBoard(ctx context.Context, request NewBoardRequest) (r NewBoardResponse, err error) {
const endpoint = "/api/boards"
req, err := c.newAuthenticatedPOSTRequest(ctx, endpoint, request)
if err != nil {
return
}
err = c.doSimpleRequest(req, &r)
if err != nil {
return
}
return
}
// GetBoard performs a get_board request against the Wekan server.
// See https://wekan.github.io/api/v5.13/#get_board
func (c *Client) GetBoard(ctx context.Context, boardID string) (r GetBoard, err error) {
var endpoint = "/api/boards/" + boardID
req, err := c.newAuthenticatedGETRequest(ctx, endpoint)
if err != nil {
return
}
err = c.doSimpleRequest(req, &r)
if err != nil {
return
}
return
}
// DeleteBoard performs a delete_board request against the Wekan server.
// See https://wekan.github.io/api/v5.13/#delete_board
func (c *Client) DeleteBoard(ctx context.Context, boardID string) (err error) {
var endpoint = "/api/boards/" + boardID
req, err := c.newAuthenticatedDELETERequest(ctx, endpoint)
if err != nil {
return
}
return c.doSimpleRequest(req, nil)
}
// GetBoardAttachments performs a get_board_attachments request against the Wekan server.
// See https://wekan.github.io/api/v5.13/#get_board_attachments
func (c *Client) GetBoardAttachments(ctx context.Context, boardID string) (attachments []BoardAttachment, err error) {
var endpoint = "/api/boards/" + boardID + "/attachments"
req, err := c.newAuthenticatedGETRequest(ctx, endpoint)
if err != nil {
return
}
err = c.doSimpleRequest(req, &attachments)
if err != nil {
return
}
return
}
// ExportJSON performs an export_json request against the Wekan server.
// See https://wekan.github.io/api/v5.13/#exportjson
func (c *Client) ExportJSON(ctx context.Context, boardID string) (boardJSON json.RawMessage, err error) {
token, err := c.token(ctx)
if err != nil {
return
}
var endpoint = "/api/boards/" + boardID + "/export?authToken=" + token
req, err := c.newGETRequest(ctx, endpoint)
if err != nil {
return
}
err = c.doSimpleRequest(req, &boardJSON)
if err != nil {
return
}
return
}
// AddBoardLabel performs an add_board_label request against the Wekan server.
// See https://wekan.github.io/api/v5.13/#add_board_label
//
// Note: Currently broken
func (c *Client) AddBoardLabel(ctx context.Context, boardID, name, color string) (err error) {
var endpoint = "/api/boards/" + boardID + "/labels"
req, err := c.newAuthenticatedPUTRequest(ctx, endpoint, addBoardLabelRequest{
Label: addBoardLabelRequestLabel{
Name: name,
Color: color,
},
})
if err != nil {
return
}
return c.doSimpleRequest(req, nil)
}
// SetBoardMemberPermission performs an set_board_member_permission request against the Wekan server.
// See https://wekan.github.io/api/v5.13/#set_board_member_permission
func (c *Client) SetBoardMemberPermission(ctx context.Context, boardID, memberID string, opts SetBoardMemberPermissionOptions) (err error) {
var endpoint = "/api/boards/" + boardID + "/members/" + memberID
req, err := c.newAuthenticatedPOSTRequest(ctx, endpoint, opts)
if err != nil {
return
}
return c.doSimpleRequest(req, nil)
}
// GetBoardsCount performs a get_boards_count request against the Wekan server.
// See https://wekan.github.io/api/v5.13/#get_boards_count
func (c *Client) GetBoardsCount(ctx context.Context) (r GetBoardsCountResponse, err error) {
const endpoint = "/api/boards_count"
req, err := c.newAuthenticatedGETRequest(ctx, endpoint)
if err != nil {
return
}
err = c.doSimpleRequest(req, &r)
if err != nil {
return
}
return
}
// GetBoardsFromUser performs a get_boards_from_user request against the Wekan server.
// See https://wekan.github.io/api/v5.13/#get_boards_from_user
func (c *Client) GetBoardsFromUser(ctx context.Context, userID string) (r []GetBoardFromUser, err error) {
var endpoint = "/api/users/" + userID + "/boards"
req, err := c.newAuthenticatedGETRequest(ctx, endpoint)
if err != nil {
return
}
err = c.doSimpleRequest(req, &r)
if err != nil {
return
}
return
}
//#############//
//### Types ###//
//#############//
type GetPublicBoard struct {
ID string `json:"_id"`
Title string `json:"title"`
}
type GetBoardFromUser struct {
ID string `json:"_id"`
Title string `json:"title"`
}
type GetBoard struct {
Title string `json:"title"`
Slug string `json:"slug"`
Archived bool `json:"archived"`
ArchivedAt time.Time `json:"archivedAt"`
CreatedAt time.Time `json:"createdAt"`
ModifiedAt time.Time `json:"modifiedAt"`
Stars int `json:"stars"`
Labels []BoardLabel `json:"labels"`
Members []BoardMember `json:"members"`
Permission string `json:"permission"`
Color string `json:"color"`
Description string `json:"description"`
SubtasksDefaultBoardID string `json:"subtasksDefaultBoardId"`
SubtasksDefaultListID string `json:"subtasksDefaultListId"`
DateSettingsDefaultBoardID string `json:"dateSettingsDefaultBoardId"`
DateSettingsDefaultListID string `json:"dateSettingsDefaultListId"`
AllowsSubtasks bool `json:"allowsSubtasks"`
AllowsAttachments bool `json:"allowsAttachments"`
AllowsChecklists bool `json:"allowsChecklists"`
AllowsComments bool `json:"allowsComments"`
AllowsDescriptionTitle bool `json:"allowsDescriptionTitle"`
AllowsDescriptionText bool `json:"allowsDescriptionText"`
AllowsActivities bool `json:"allowsActivities"`
AllowsLabels bool `json:"allowsLabels"`
AllowsAssignee bool `json:"allowsAssignee"`
AllowsMembers bool `json:"allowsMembers"`
AllowsRequestedBy bool `json:"allowsRequestedBy"`
AllowsAssignedBy bool `json:"allowsAssignedBy"`
AllowsReceivedDate bool `json:"allowsReceivedDate"`
AllowsStartDate bool `json:"allowsStartDate"`
AllowsEndDate bool `json:"allowsEndDate"`
AllowsDueDate bool `json:"allowsDueDate"`
PresentParentTask string `json:"presentParentTask"`
StartAt string `json:"startAt"`
DueAt string `json:"dueAt"`
EndAt string `json:"endAt"`
SpentTime int `json:"spentTime"`
IsOvertime bool `json:"isOvertime"`
Type string `json:"type"`
Sort int `json:"sort"`
}
type BoardLabel struct {
ID string `json:"_id"`
Name string `json:"name"`
Color string `json:"color"`
}
type BoardMember struct {
UserID string `json:"userId"`
IsAdmin bool `json:"isAdmin"`
IsActive bool `json:"isActive"`
IsNoComments bool `json:"isNoComments"`
IsCommentOnly bool `json:"isCommentOnly"`
IsWorker bool `json:"isWorker"`
}
type BoardAttachment struct {
AttachmentID string `json:"attachmentId"`
AttachmentName string `json:"attachmentName"`
AttachmentType string `json:"attachmentType"`
CardID string `json:"cardId"`
ListID string `json:"listId"`
SwimlaneID string `json:"swimlaneId"`
}
type NewBoardRequest struct {
// Required
Title string `json:"title"`
Owner string `json:"owner"`
// Optional
NewBoardOptions `json:",inline"`
}
type NewBoardOptions struct {
IsAdmin bool `json:"isAdmin"`
IsActive bool `json:"isActive"`
IsNoComments bool `json:"isNoComments"`
IsCommentOnly bool `json:"isCommentOnly"`
IsWorker bool `json:"isWorker"`
Permission string `json:"permission"`
Color string `json:"color"`
}
type NewBoardResponse struct {
ID string `json:"_id"`
DefaultSwimlaneID string `json:"defaultSwimlaneId"`
}
type addBoardLabelRequest struct {
Label addBoardLabelRequestLabel `json:"label"`
}
type addBoardLabelRequestLabel struct {
Name string `json:"name"`
Color string `json:"color"`
}
type SetBoardMemberPermissionOptions struct {
IsAdmin bool `json:"isAdmin"`
IsNoComments bool `json:"isNoComments"`
IsCommentOnly bool `json:"isCommentOnly"`
IsWorker bool `json:"isWorker"`
}
type GetBoardsCountResponse struct {
Private int `json:"private"`
Public int `json:"public"`
}