-
Notifications
You must be signed in to change notification settings - Fork 1
/
updates.go
147 lines (128 loc) · 3.81 KB
/
updates.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
package monday
// UpdateService handles all the update related methods of the Monday API.
// Updates are additional notes and information added to items outside of the structure of the board.
// The main form of communication within the platform takes place in the updates section.
type UpdateService service
// Create returns a mutation that allows you to add an update to a item.
// After the mutation runs you can query back all the board data.
// - id: the item's unique identifier.
// - body: the update text.
//
// DOCS: https://monday.com/developers/v2#mutations-section-updates
func (*UpdateService) Create(id int, body string, updatesFields []UpdatesField) Mutation {
if len(updatesFields) == 0 {
updatesFields = append(updatesFields, updatesIDField)
}
var fields []field
for _, uf := range updatesFields {
fields = append(fields, uf.field)
}
return Mutation{
name: "create_update",
fields: fields,
args: []argument{
{"item_id", id},
{"body", body},
},
}
}
// List returns a query that gets one or a collection of updates.
//
// DOCS: https://monday.com/developers/v2#queries-section-updates
func (*UpdateService) List(updatesFields []UpdatesField, updatesArgs ...UpdatesArgument) Query {
if len(updatesFields) == 0 {
return Query{
name: "updates",
fields: []field{
UpdatesIDField().field,
},
}
}
var fields []field
for _, uf := range updatesFields {
fields = append(fields, uf.field)
}
var args []argument
for _, ua := range updatesArgs {
args = append(args, ua.arg)
}
return Query{
name: "updates",
fields: fields,
args: args,
}
}
// The update's graphql field(s).
type UpdatesField struct {
field field
}
var (
updatesBodyField = UpdatesField{field{"body", nil}}
updatesCreatedAtField = UpdatesField{field{"created_at", nil}}
updatesCreatorIDField = UpdatesField{field{"creator_id", nil}}
updatesIDField = UpdatesField{field{"id", nil}}
updatesItemIDField = UpdatesField{field{"item_id", nil}}
updatesTextBodyField = UpdatesField{field{"text_body", nil}}
updatesUpdatedAtField = UpdatesField{field{"updated_at", nil}}
)
// The update's html formatted body.
func UpdatesBodyField() UpdatesField {
return updatesBodyField
}
// The update's creation date.
func UpdatesCreatedAtField() UpdatesField {
return updatesCreatedAtField
}
// The update's creator.
func NewUpdatesCreatorField(creatorFields []UsersField, creatorArgs ...UsersArgument) UpdatesField {
creator := Users.List(creatorFields, creatorArgs...)
creator.name = "creator"
return UpdatesField{field{creator.name, &creator}}
}
// The unique identifier of the update creator.
func UpdatesCreatorIDField() UpdatesField {
return updatesCreatorIDField
}
// The update's unique identifier.
func UpdatesIDField() UpdatesField {
return updatesIDField
}
// The update's item ID.
func UpdatesItemIDField() UpdatesField {
return updatesItemIDField
}
// The update's replies.
func NewUpdatesRepliesField(repliesFields []RepliesField) UpdatesField {
var fields []field
for _, rf := range repliesFields {
fields = append(fields, rf.field)
}
if len(fields) == 0 {
fields = append(fields, RepliesIDField().field)
}
replies := Query{
name: "replies",
fields: fields,
}
return UpdatesField{field{"replies", &replies}}
}
// The update's text body.
func UpdatesTextBodyField() UpdatesField {
return updatesTextBodyField
}
// The update's last edit date.
func UpdatesUpdatedAtField() UpdatesField {
return updatesUpdatedAtField
}
// The update's graphql argument(s).
type UpdatesArgument struct {
arg argument
}
// Number of items to get, the default is 25.
func NewUpdatesLimitArgument(value int) UpdatesArgument {
return UpdatesArgument{argument{"limit", value}}
}
// Page number to get, starting at 1.
func NewUpdatesPageArgument(value int) UpdatesArgument {
return UpdatesArgument{argument{"page", value}}
}