-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathclient_cards.go
285 lines (242 loc) · 9.25 KB
/
client_cards.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
/**
* Copyright (c) 2023 Sebastian Borchers
*
* This software is released under the MIT License.
* https://opensource.org/licenses/MIT
*/
package wego
import (
"context"
"errors"
"io"
"time"
)
// GetCardsByCustomField performs a get_cards_by_custom_field request against the Wekan server.
// See https://wekan.github.io/api/v5.13/#get_cards_by_custom_field
func (c *Client) GetCardsByCustomField(ctx context.Context, boardID, customField, customFieldValue string) (cards []GetCardByCustomField, err error) {
var endpoint = c.endpoint("boards", boardID, "cardsByCustomField", customField, customFieldValue)
req, err := c.newAuthenticatedGETRequest(ctx, endpoint)
if err != nil {
return
}
err = c.doSimpleRequest(req, &cards)
if err != nil {
return
}
return
}
// GetAllCards performs a get_all_cards request against the Wekan server.
// See https://wekan.github.io/api/v5.13/#get_all_cards
func (c *Client) GetAllCards(ctx context.Context, boardID, listID string) (cards []GetAllCard, err error) {
var endpoint = c.endpoint("boards", boardID, "lists", listID, "cards")
req, err := c.newAuthenticatedGETRequest(ctx, endpoint)
if err != nil {
return
}
err = c.doSimpleRequest(req, &cards)
if err != nil {
return
}
return
}
// NewCard performs a new_card request against the Wekan server.
// See https://wekan.github.io/api/v5.13/#new_card
func (c *Client) NewCard(ctx context.Context, boardID, listID string, request NewCardRequest) (r NewCardResponse, err error) {
var endpoint = c.endpoint("boards", boardID, "lists", listID, "cards")
req, err := c.newAuthenticatedPOSTRequest(ctx, endpoint, request)
if err != nil {
return
}
err = c.doSimpleRequest(req, &r)
if err != nil {
return
}
return
}
// GetCard performs a get_card request against the Wekan server.
// See https://wekan.github.io/api/v5.13/#get_card
//
// Returns ErrNotFound, if the card could not be found.
func (c *Client) GetCard(ctx context.Context, boardID, listID, cardID string) (card GetCard, err error) {
var endpoint = c.endpoint("boards", boardID, "lists", listID, "cards", cardID)
req, err := c.newAuthenticatedGETRequest(ctx, endpoint)
if err != nil {
return
}
err = c.doSimpleRequest(req, &card)
if err != nil {
if errors.Is(err, io.EOF) {
err = ErrNotFound
}
return
}
return
}
// EditCard performs a edit_card request against the Wekan server.
// See https://wekan.github.io/api/v5.13/#edit_card
func (c *Client) EditCard(ctx context.Context, boardID, listID, cardID string, opts EditCardOptions) (r EditCardResponse, err error) {
endpoint := c.endpoint("boards", boardID, "lists", listID, "cards", cardID)
req, err := c.newAuthenticatedPUTRequest(ctx, endpoint, opts)
if err != nil {
return
}
err = c.doSimpleRequest(req, &r)
if err != nil {
return
}
return
}
// DeleteCard performs a delete_card request against the Wekan server.
// See https://wekan.github.io/api/v5.13/#delete_card
func (c *Client) DeleteCard(ctx context.Context, boardID, cardID string) (err error) {
var endpoint = "/api/boards/" + boardID + "/cards/" + cardID
req, err := c.newAuthenticatedDELETERequest(ctx, endpoint)
if err != nil {
return
}
return c.doSimpleRequest(req, nil)
}
// GetSwimlaneCards performs a get_swimlane_cards request against the Wekan server.
// See https://wekan.github.io/api/v5.13/#get_swimlane_cards
func (c *Client) GetSwimlaneCards(ctx context.Context, boardID, swimlaneID string) (cards []GetSwimlaneCard, err error) {
var endpoint = c.endpoint("boards", boardID, "swimlanes", swimlaneID, "cards")
req, err := c.newAuthenticatedGETRequest(ctx, endpoint)
if err != nil {
return
}
err = c.doSimpleRequest(req, &cards)
if err != nil {
return
}
return
}
//#############//
//### Types ###//
//#############//
type GetAllCard struct {
ID string `json:"_id"`
Title string `json:"title"`
Description string `json:"description"`
}
type GetCardByCustomField struct {
ID string `json:"_id"`
Title string `json:"title"`
Description string `json:"description"`
ListID string `json:"listId"`
SwimlaneID string `json:"swimlaneId"`
}
type GetSwimlaneCard struct {
ID string `json:"_id"`
Title string `json:"title"`
Description string `json:"description"`
ListID string `json:"listId"`
}
type NewCardRequest struct {
// Required
AuthorID string `json:"authorId"`
Title string `json:"title"`
Description string `json:"description"`
SwimlaneID string `json:"swimlaneId"`
// Optional
NewCardOptions `json:",inline"`
}
type NewCardOptions struct {
MemberIDs []string `json:"members,omitempty"`
Assignees []string `json:"assignees,omitempty"`
}
type NewCardResponse struct {
ID string `json:"_id"`
}
type GetCard struct {
Title string `json:"title"`
Archived bool `json:"archived"`
ArchivedAt string `json:"archivedAt"`
ParentID string `json:"parentId"`
ListID string `json:"listId"`
SwimlaneID string `json:"swimlaneId"`
BoardID string `json:"boardId"`
CoverID string `json:"coverId"`
Color string `json:"color"`
CreatedAt string `json:"createdAt"`
ModifiedAt string `json:"modifiedAt"`
CustomFields []CardCustomField `json:"customFields"`
DateLastActivity string `json:"dateLastActivity"`
Description string `json:"description"`
RequestedBy string `json:"requestedBy"`
AssignedBy string `json:"assignedBy"`
LabelIds []string `json:"labelIds"`
Members []string `json:"members"`
Assignees []string `json:"assignees"`
ReceivedAt string `json:"receivedAt"`
StartAt string `json:"startAt"`
DueAt string `json:"dueAt"`
EndAt string `json:"endAt"`
SpentTime int `json:"spentTime"`
IsOvertime bool `json:"isOvertime"`
UserID string `json:"userId"`
Sort float64 `json:"sort"`
SubtaskSort int `json:"subtaskSort"`
Type string `json:"type"`
LinkedID string `json:"linkedId"`
Vote Vote `json:"vote"`
Poker Poker `json:"poker"`
TargetIDGantt []string `json:"targetId_gantt"`
LinkTypeGantt []int `json:"linkType_gantt"`
LinkIDGantt []string `json:"linkId_gantt"`
CardNumber int `json:"cardNumber"`
}
type CardCustomField struct {
ID string `json:"_id"`
Value any `json:"value"`
}
type Vote struct {
Question string `json:"question,omitempty"`
Positive []string `json:"positive,omitempty"`
Negative []string `json:"negative,omitempty"`
End string `json:"end,omitempty"`
Public bool `json:"public,omitempty"`
AllowNonBoardMembers bool `json:"allowNonBoardMembers,omitempty"`
}
type Poker struct {
Question bool `json:"question,omitempty"`
One []string `json:"one,omitempty"`
Two []string `json:"two,omitempty"`
Three []string `json:"three,omitempty"`
Five []string `json:"five,omitempty"`
Eight []string `json:"eight,omitempty"`
Thirteen []string `json:"thirteen,omitempty"`
Twenty []string `json:"twenty,omitempty"`
Forty []string `json:"forty,omitempty"`
OneHundred []string `json:"oneHundred,omitempty"`
Unsure []string `json:"unsure,omitempty"`
End string `json:"end,omitempty"`
AllowNonBoardMembers bool `json:"allowNonBoardMembers,omitempty"`
Estimation int `json:"estimation,omitempty"`
}
type EditCardOptions struct {
Title string `json:"title,omitempty"`
Sort string `json:"sort,omitempty"`
ParentID string `json:"parentId,omitempty"`
Description string `json:"description,omitempty"`
Color string `json:"color,omitempty"`
Vote *Vote `json:"vote,omitempty"`
Poker *Poker `json:"poker,omitempty"`
LabelIDs []string `json:"labelIds,omitempty"`
RequestedBy string `json:"requestedBy,omitempty"`
AssignedBy string `json:"assignedBy,omitempty"`
ReceivedAt *time.Time `json:"receivedAt,omitempty"`
StartAt *time.Time `json:"startAt,omitempty"`
DueAt *time.Time `json:"dueAt,omitempty"`
EndAt *time.Time `json:"endAt,omitempty"`
SpentTime string `json:"spentTime,omitempty"`
IsOverTime bool `json:"isOverTime,omitempty"`
CustomFields []CardCustomField `json:"customFields,omitempty"`
Members []string `json:"members,omitempty"`
Assignees []string `json:"assignees,omitempty"`
SwimlaneID string `json:"swimlaneId,omitempty"`
ListID string `json:"listId,omitempty"`
AuthorID string `json:"authorId,omitempty"`
}
type EditCardResponse struct {
ID string `json:"_id"`
}