You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: zendesk/ticket.go
+160-1Lines changed: 160 additions & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -129,6 +129,9 @@ type Via struct {
129
129
} `json:"source"`
130
130
}
131
131
132
+
// TicketListOptions struct is used to specify options for listing tickets in OBP (Offset Based Pagination).
133
+
// It embeds the PageOptions struct for pagination and provides options for sorting the result;
134
+
// SortBy specifies the field to sort by, and SortOrder specifies the order (either 'asc' or 'desc').
132
135
typeTicketListOptionsstruct {
133
136
PageOptions
134
137
@@ -140,9 +143,119 @@ type TicketListOptions struct {
140
143
SortOrderstring`url:"sort_order,omitempty"`
141
144
}
142
145
146
+
// TicketListCBPOptions struct is used to specify options for listing tickets in CBP (Cursor Based Pagination).
147
+
// It embeds the CursorPagination struct for pagination and provides an option Sort for sorting the result.
148
+
typeTicketListCBPOptionsstruct {
149
+
CursorPagination
150
+
Sortstring`url:"sort,omitempty"`
151
+
}
152
+
153
+
// TicketListCBPResult struct represents the result of a ticket list operation in CBP. It includes an array of Ticket objects, and Meta that holds pagination metadata.
154
+
typeTicketListCBPResultstruct {
155
+
Tickets []Ticket`json:"tickets"`
156
+
MetaCursorPaginationMeta`json:"meta"`
157
+
}
158
+
159
+
// PaginationOptions struct represents general pagination options.
160
+
// PageSize specifies the number of items per page, IsCBP indicates if it's cursor-based pagination,
161
+
// SortBy and SortOrder describe how to sort the items in Offset Based Pagination, and Sort describes how to sort items in Cursor Based Pagination.
162
+
typePaginationOptionsstruct {
163
+
PageSizeint//default is 100
164
+
IsCBPbool//default is true
165
+
166
+
SortBystring
167
+
// SortOrder can take "asc" or "desc"
168
+
SortOrderstring
169
+
Sortstring
170
+
}
171
+
172
+
// NewPaginationOptions() returns a pointer to a new PaginationOptions struct with default values (PageSize is 100, IsCBP is true).
173
+
funcNewPaginationOptions() *PaginationOptions {
174
+
return&PaginationOptions{
175
+
PageSize: 100,
176
+
IsCBP: true,
177
+
}
178
+
}
179
+
180
+
// TicketIterator struct provides a convenient way to iterate over pages of tickets in either OBP or CBP.
181
+
// It holds state for iteration, including the current page size, a flag indicating more pages, pagination type (OBP or CBP), and sorting options.
182
+
typeTicketIteratorstruct {
183
+
// generic fields
184
+
pageSizeint
185
+
hasMorebool
186
+
isCBPbool
187
+
188
+
// OBP fields
189
+
sortBystring
190
+
// SortOrder can take "asc" or "desc"
191
+
sortOrderstring
192
+
pageIndexint
193
+
194
+
// CBP fields
195
+
sortstring
196
+
pageAfterstring
197
+
198
+
// common fields
199
+
client*Client
200
+
ctx context.Context
201
+
}
202
+
203
+
// HasMore() returns a boolean indicating whether more pages are available for iteration.
204
+
func (i*TicketIterator) HasMore() bool {
205
+
returni.hasMore
206
+
}
207
+
208
+
// GetNext() retrieves the next batch of tickets according to the current pagination and sorting options.
209
+
// It updates the state of the iterator for subsequent calls.
210
+
// In case of an error, it sets hasMore to false and returns an error.
0 commit comments