forked from desertbit/wego
-
Notifications
You must be signed in to change notification settings - Fork 0
/
client_cards.go
251 lines (210 loc) · 7.4 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
/**
* 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"
)
// 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
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 {
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, nil)
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"`
Assignees []string `json:"assignees"`
}
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 json.RawMessage `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 int `json:"sort"`
SubtaskSort int `json:"subtaskSort"`
Type string `json:"type"`
LinkedID string `json:"linkedId"`
Vote CardVote `json:"vote"`
}
type CardVote struct {
Question string `json:"question"`
Positive []string `json:"positive"`
Negative []string `json:"negative"`
End string `json:"end"`
Public bool `json:"public"`
AllowNonBoardMembers bool `json:"allowNonBoardMembers"`
}
type EditCardOptions struct {
Title string `json:"title"`
Sort string `json:"sort"`
ParentID string `json:"parentId"`
Description string `json:"description"`
Color string `json:"color"`
Vote CardVote `json:"vote"`
LabelIDs []string `json:"labelIds"`
RequestedBy string `json:"requestedBy"`
AssignedBy string `json:"assignedBy"`
ReceivedAt time.Time `json:"receivedAt"`
StartAt time.Time `json:"startAt"`
DueAt time.Time `json:"dueAt"`
EndAt time.Time `json:"endAt"`
SpentTime string `json:"spentTime"`
IsOverTime bool `json:"isOverTime"`
CustomFields string `json:"customFields"`
Members []string `json:"members"`
Assignees []string `json:"assignees"`
SwimlaneID string `json:"swimlaneId"`
ListID string `json:"listId"`
AuthorID string `json:"authorId"`
}
type EditCardResponse struct {
ID string `json:"_id"`
}