This repository was archived by the owner on Dec 22, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathgroups.go
More file actions
205 lines (182 loc) · 5.59 KB
/
groups.go
File metadata and controls
205 lines (182 loc) · 5.59 KB
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
package monday
// GroupsService handles all the group related methods of the Monday API.
// Items are grouped together in units called groups.
// Each board contains one or multiple groups, and each group can hold one or many items.
type GroupsService service
// Duplicate returns a mutation that duplicates a group with all of its items.
// - boardID: the board's unique identifier.
// - groupID: the group's unique identifier.
// - top: should the new group be added to the top?
//
// DOCS: https://monday.com/developers/v2#mutations-section-groups-duplicate
func (*GroupsService) Duplicate(boardID int, groupID string, top bool, groupsFields []GroupsField) Mutation {
if len(groupsFields) == 0 {
groupsFields = append(groupsFields, groupsIDField)
}
var fields []field
for _, gf := range groupsFields {
fields = append(fields, gf.field)
}
return Mutation{
name: "duplicate_group",
fields: fields,
args: []argument{
{"board_id", boardID},
{"group_id", groupID},
{"add_to_top", top},
},
}
}
// DuplicateWithNewTitle returns a mutation that duplicates a group with all of its items.
// - boardID: the board's unique identifier.
// - groupID: the group's unique identifier.
// - top: should the new group be added to the top?
// - title: the group's title.
//
// DOCS: https://monday.com/developers/v2#mutations-section-groups-duplicate
func (*GroupsService) DuplicateWithNewTitle(boardID int, groupID string, top bool, title string, groupsFields []GroupsField) Mutation {
group := Groups.Duplicate(boardID, groupID, top, groupsFields)
group.args = append(group.args, argument{"group_title", title})
return group
}
// Create returns a mutation that creates a new empty group.
// - boardID: the board's unique identifier.
// - groupID: The group's unique identifier.
//
// DOCS: https://monday.com/developers/v2#mutations-section-groups-create
func (*GroupsService) Create(boardID int, groupName string, groupsFields []GroupsField) Mutation {
if len(groupsFields) == 0 {
groupsFields = append(groupsFields, groupsIDField)
}
var fields []field
for _, gf := range groupsFields {
fields = append(fields, gf.field)
}
return Mutation{
name: "create_group",
fields: fields,
args: []argument{
{"board_id", boardID},
{"group_name", groupName},
},
}
}
// Archive returns a mutation that archives a group with all of its items.
// - boardID: the board's unique identifier.
// - groupID: The group's unique identifier.
//
// DOCS: https://monday.com/developers/v2#mutations-section-groups-archive
func (*GroupsService) Archive(boardID int, groupID string, groupsFields []GroupsField) Mutation {
if len(groupsFields) == 0 {
groupsFields = append(groupsFields, groupsIDField)
}
var fields []field
for _, gf := range groupsFields {
fields = append(fields, gf.field)
}
return Mutation{
name: "archive_group",
fields: fields,
args: []argument{
{"board_id", boardID},
{"group_id", groupID},
},
}
}
// Delete returns a mutation that deletes a group with all of its items.
// - boardID: the board's unique identifier.
// - groupID: The group's unique identifier.
//
// DOCS: https://monday.com/developers/v2#mutations-section-groups-delete
func (*GroupsService) Delete(boardID int, groupID string, groupsFields []GroupsField) Mutation {
if len(groupsFields) == 0 {
groupsFields = append(groupsFields, groupsIDField)
}
var fields []field
for _, gf := range groupsFields {
fields = append(fields, gf.field)
}
return Mutation{
name: "delete_group",
fields: fields,
args: []argument{
{"board_id", boardID},
{"group_id", groupID},
},
}
}
// List returns a query that gets one group or a collection of groups in a specific board.
//
// DOCS: https://monday.com/developers/v2#queries-section-groups
func (*GroupsService) list(groupsFields []GroupsField, groupsArgs ...GroupsArgument) Query {
if len(groupsFields) == 0 {
return Query{
name: "groups",
fields: []field{
GroupsIDField().field,
},
}
}
var fields []field
for _, gf := range groupsFields {
fields = append(fields, gf.field)
}
var args []argument
for _, ga := range groupsArgs {
args = append(args, ga.arg)
}
return Query{
name: "groups",
fields: fields,
args: args,
}
}
// The group's graphql field(s).
type GroupsField struct {
field field
}
var (
groupsArchivedField = GroupsField{field{"archived", nil}}
groupsColorField = GroupsField{field{"color", nil}}
groupsDeletedField = GroupsField{field{"deleted", nil}}
groupsIDField = GroupsField{field{"id", nil}}
groupsPositionField = GroupsField{field{"position", nil}}
groupsTitleField = GroupsField{field{"title", nil}}
)
// Is the group archived or not.
func GroupsArchivedField() GroupsField {
return groupsArchivedField
}
// The group's color.
func GroupsColorField() GroupsField {
return groupsColorField
}
// Is the group deleted or not.
func GroupsDeletedField() GroupsField {
return groupsDeletedField
}
// The group's unique identifier.
func GroupsIDField() GroupsField {
return groupsIDField
}
// The items in the group.
func NewGroupsItemsField(itemsFields []ItemsField, itemsArgs []ItemsArgument) GroupsField {
items := Items.List(itemsFields, itemsArgs...)
return GroupsField{field{"items", &items}}
}
// The group's position in the board.
func GroupsPositionField() GroupsField {
return groupsPositionField
}
// The group's title.
func GroupsTitleField() GroupsField {
return groupsTitleField
}
// The group's graphql argument(s).
type GroupsArgument struct {
arg argument
}
// A list of group unique identifiers.
func NewGroupsIDsArgument(ids []string) GroupsArgument {
return GroupsArgument{argument{"ids", ids}}
}