forked from desertbit/wego
-
Notifications
You must be signed in to change notification settings - Fork 0
/
client_customFields.go
189 lines (150 loc) · 5.53 KB
/
client_customFields.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
/**
* Copyright (c) 2023 Sebastian Borchers
*
* This software is released under the MIT License.
* https://opensource.org/licenses/MIT
*/
package wego
import "context"
// GetAllCustomFields performs a get_all_custom_fields request against the Wekan server.
// See https://wekan.github.io/api/v5.13/#get_all_custom_fields
func (c *Client) GetAllCustomFields(ctx context.Context, boardID string) (fields []GetAllCustomField, err error) {
endpoint := c.endpoint("boards", boardID, "custom-fields")
req, err := c.newAuthenticatedGETRequest(ctx, endpoint)
if err != nil {
return
}
err = c.doSimpleRequest(req, &fields)
if err != nil {
return
}
return
}
// NewCustomField performs a new_custom_field request against the Wekan server.
// See https://wekan.github.io/api/v5.13/#new_custom_field
func (c *Client) NewCustomField(ctx context.Context, boardID string, data NewCustomFieldRequest) (r NewCustomFieldResponse, err error) {
endpoint := c.endpoint("boards", boardID, "custom-fields")
req, err := c.newAuthenticatedPOSTRequest(ctx, endpoint, data)
if err != nil {
return
}
err = c.doSimpleRequest(req, &r)
if err != nil {
return
}
return
}
// GetCustomField performs a get_custom_field request against the Wekan server.
// See https://wekan.github.io/api/v5.13/#get_all_custom_fields
func (c *Client) GetCustomField(ctx context.Context, boardID string) (resp []GetCustomField, err error) {
endpoint := c.endpoint("boards", boardID, "custom-fields")
req, err := c.newAuthenticatedGETRequest(ctx, endpoint)
if err != nil {
return
}
err = c.doSimpleRequest(req, &resp)
if err != nil {
return
}
return
}
// EditCustomField performs a edit_custom_field request against the Wekan server.
// See https://wekan.github.io/api/v5.13/#edit_custom_field
func (c *Client) EditCustomField(ctx context.Context, boardID string, data EditCustomFieldRequest) (r EditCustomFieldResponse, err error) {
endpoint := c.endpoint("boards", boardID, "custom-fields")
req, err := c.newAuthenticatedPUTRequest(ctx, endpoint, data)
if err != nil {
return
}
err = c.doSimpleRequest(req, &r)
if err != nil {
return
}
return
}
// DeleteCustomField performs a delete_custom_field request against the Wekan server.
// See https://wekan.github.io/api/v5.13/#delete_custom_field
func (c *Client) DeleteCustomField(ctx context.Context, boardID, customFieldID string) (err error) {
endpoint := c.endpoint("boards", boardID, "custom-fields", customFieldID)
req, err := c.newAuthenticatedDELETERequest(ctx, endpoint)
if err != nil {
return
}
return c.doSimpleRequest(req, nil)
}
// AddCustomFieldDropdownItems performs a add_custom_field_dropdown_items request against the Wekan server.
// See https://wekan.github.io/api/v5.13/#add_custom_field_dropdown_items
func (c *Client) AddCustomFieldDropdownItems(ctx context.Context, boardID, customFieldID string, items []string) (err error) {
endpoint := c.endpoint("boards", boardID, "custom-fields", customFieldID, "dropdown-items")
req, err := c.newAuthenticatedPOSTRequest(ctx, endpoint, addCustomFieldDropdownItemsRequest{
Items: items,
})
if err != nil {
return
}
return c.doSimpleRequest(req, nil)
}
// EditCustomFieldDropdownItems performs a edit_custom_field_dropdown_items request against the Wekan server.
// See https://wekan.github.io/api/v5.13/#edit_custom_field_dropdown_items
func (c *Client) EditCustomFieldDropdownItems(ctx context.Context, boardID, customFieldID, dropdownItem, name string) (err error) {
endpoint := c.endpoint("boards", boardID, "custom-fields", customFieldID, "dropdown-items", dropdownItem)
req, err := c.newAuthenticatedPUTRequest(ctx, endpoint, editCustomFieldDropdownItemsRequest{
Name: name,
})
if err != nil {
return
}
return c.doSimpleRequest(req, nil)
}
// DeleteCustomFieldDropdownItem performs a delete_custom_field request against the Wekan server.
// See https://wekan.github.io/api/v5.13/#delete_custom_field_dropdown_item
func (c *Client) DeleteCustomFieldDropdownItem(ctx context.Context, boardID, customFieldID, dropdownItem string) (err error) {
endpoint := c.endpoint("boards", boardID, "custom-fields", customFieldID, "dropdown-items", dropdownItem)
req, err := c.newAuthenticatedDELETERequest(ctx, endpoint)
if err != nil {
return
}
return c.doSimpleRequest(req, nil)
}
//#############//
//### Types ###//
//#############//
type GetAllCustomField struct {
ID string `json:"_id"`
Name string `json:"name"`
Type string `json:"type"`
}
type NewCustomFieldRequest struct {
Name string `json:"name"`
Type string `json:"type"`
Settings string `json:"settings"`
ShowOnCard bool `json:"showOnCard"`
AutomaticallyOnCard bool `json:"automaticallyOnCard"`
ShowLabelOnMiniCard bool `json:"showLabelOnMiniCard"`
AuthorId string `json:"authorId"`
}
type NewCustomFieldResponse struct {
ID string `json:"_id"`
}
type GetCustomField struct {
ID string `json:"_id"`
BoardIDs string `json:"boardIds"`
}
type EditCustomFieldRequest struct {
Name string `json:"name"`
Type string `json:"type"`
Settings string `json:"settings"`
ShowOnCard bool `json:"showOnCard"`
AutomaticallyOnCard bool `json:"automaticallyOnCard"`
AlwaysOnCard bool `json:"alwaysOnCard"`
ShowLabelOnMiniCard bool `json:"showLabelOnMiniCard"`
}
type EditCustomFieldResponse struct {
ID string `json:"_id"`
}
type addCustomFieldDropdownItemsRequest struct {
Items []string `json:"items"`
}
type editCustomFieldDropdownItemsRequest struct {
Name string `json:"name"`
}