From 80ebaea1891ad9d064cf8756d0e138149d2b4a4a Mon Sep 17 00:00:00 2001 From: Arthur Bols Date: Wed, 13 Jul 2022 08:16:03 +0200 Subject: [PATCH 1/3] Add GroupListOptions to GetGroups This adds support for pagination to GetGroups --- zendesk/group.go | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/zendesk/group.go b/zendesk/group.go index 93629c2d..fb544af9 100644 --- a/zendesk/group.go +++ b/zendesk/group.go @@ -20,9 +20,16 @@ type Group struct { UpdatedAt time.Time `json:"updated_at,omitempty"` } +// GroupListOptions is options for GetGroups +// +// ref: https://developer.zendesk.com/rest_api/docs/support/groups#list-groups +type GroupListOptions struct { + PageOptions +} + // GroupAPI an interface containing all methods associated with zendesk groups type GroupAPI interface { - GetGroups(ctx context.Context) ([]Group, Page, error) + GetGroups(ctx context.Context, opts *GroupListOptions) ([]Group, Page, error) GetGroup(ctx context.Context, groupID int64) (Group, error) CreateGroup(ctx context.Context, group Group) (Group, error) UpdateGroup(ctx context.Context, groupID int64, group Group) (Group, error) @@ -31,13 +38,23 @@ type GroupAPI interface { // GetGroups fetches group list // https://developer.zendesk.com/rest_api/docs/support/groups#list-groups -func (z *Client) GetGroups(ctx context.Context) ([]Group, Page, error) { +func (z *Client) GetGroups(ctx context.Context, opts *GroupListOptions) ([]Group, Page, error) { var data struct { Groups []Group `json:"groups"` Page } - body, err := z.get(ctx, "/groups.json") + tmp := opts + if tmp == nil { + tmp = &GroupListOptions{} + } + + u, err := addOptions("/groups.json", tmp) + if err != nil { + return []Group{}, Page{}, err + } + + body, err := z.get(ctx, u) if err != nil { return []Group{}, Page{}, err } From 9215bc4222cbe0bfd047ef2215a381d85afdf6d9 Mon Sep 17 00:00:00 2001 From: Arthur Bols Date: Wed, 13 Jul 2022 08:19:42 +0200 Subject: [PATCH 2/3] Update GetGroups test --- zendesk/group_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/zendesk/group_test.go b/zendesk/group_test.go index b0956e50..c707dc05 100644 --- a/zendesk/group_test.go +++ b/zendesk/group_test.go @@ -11,7 +11,7 @@ func TestGetGroups(t *testing.T) { client := newTestClient(mockAPI) defer mockAPI.Close() - groups, _, err := client.GetGroups(ctx) + groups, _, err := client.GetGroups(ctx, nil) if err != nil { t.Fatalf("Failed to get groups: %s", err) } From c395468b260bc774cf9af005b8b0b606f1276c27 Mon Sep 17 00:00:00 2001 From: Arthur Bols Date: Wed, 13 Jul 2022 08:20:45 +0200 Subject: [PATCH 3/3] Generate mocks for updated GetGroups --- zendesk/mock/client.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/zendesk/mock/client.go b/zendesk/mock/client.go index b7e9e2db..571177b3 100644 --- a/zendesk/mock/client.go +++ b/zendesk/mock/client.go @@ -700,9 +700,9 @@ func (mr *ClientMockRecorder) GetGroupMemberships(arg0, arg1 interface{}) *gomoc } // GetGroups mocks base method. -func (m *Client) GetGroups(arg0 context.Context) ([]zendesk.Group, zendesk.Page, error) { +func (m *Client) GetGroups(arg0 context.Context, arg1 *zendesk.GroupListOptions) ([]zendesk.Group, zendesk.Page, error) { m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "GetGroups", arg0) + ret := m.ctrl.Call(m, "GetGroups", arg0, arg1) ret0, _ := ret[0].([]zendesk.Group) ret1, _ := ret[1].(zendesk.Page) ret2, _ := ret[2].(error) @@ -710,9 +710,9 @@ func (m *Client) GetGroups(arg0 context.Context) ([]zendesk.Group, zendesk.Page, } // GetGroups indicates an expected call of GetGroups. -func (mr *ClientMockRecorder) GetGroups(arg0 interface{}) *gomock.Call { +func (mr *ClientMockRecorder) GetGroups(arg0, arg1 interface{}) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetGroups", reflect.TypeOf((*Client)(nil).GetGroups), arg0) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetGroups", reflect.TypeOf((*Client)(nil).GetGroups), arg0, arg1) } // GetLocales mocks base method.