diff --git a/script/codegen/main.go b/script/codegen/main.go index 56cff823..c0635d0c 100644 --- a/script/codegen/main.go +++ b/script/codegen/main.go @@ -217,6 +217,14 @@ var funcData []FuncTemplateData = []FuncTemplateData{ FileName: "organization_users", ExtraParam: true, }, + { + FuncName: "GroupUsers", + ObjectName: "User", + ApiEndpoint: "/groups/%d/users.json", + JsonName: "users", + FileName: "group_users", + ExtraParam: true, + }, { FuncName: "Views", ObjectName: "View", diff --git a/zendesk/group_users_generated.go b/zendesk/group_users_generated.go new file mode 100644 index 00000000..47ad61b0 --- /dev/null +++ b/zendesk/group_users_generated.go @@ -0,0 +1,79 @@ + +// Code generated by Script. DO NOT EDIT. +// Source: script/codegen/main.go +// +// Generated by this command: +// +// go run script/codegen/main.go + +package zendesk + +import ( + "context" + "fmt" +) + +func (z *Client) GetGroupUsersIterator(ctx context.Context, opts *PaginationOptions) *Iterator[User] { + return &Iterator[User]{ + CommonOptions: opts.CommonOptions, + pageSize: opts.PageSize, + hasMore: true, + isCBP: opts.IsCBP, + pageAfter: "", + pageIndex: 1, + ctx: ctx, + obpFunc: z.GetGroupUsersOBP, + cbpFunc: z.GetGroupUsersCBP, + } +} + +func (z *Client) GetGroupUsersOBP(ctx context.Context, opts *OBPOptions) ([]User, Page, error) { + var data struct { + Users []User `json:"users"` + Page + } + + tmp := opts + if tmp == nil { + tmp = &OBPOptions{} + } + + path := fmt.Sprintf("/groups/%d/users.json", tmp.Id) + u, err := addOptions(path, tmp) + + if err != nil { + return nil, Page{}, err + } + + err = getData(z, ctx, u, &data) + if err != nil { + return nil, Page{}, err + } + return data.Users, data.Page, nil +} + +func (z *Client) GetGroupUsersCBP(ctx context.Context, opts *CBPOptions) ([]User, CursorPaginationMeta, error) { + var data struct { + Users []User `json:"users"` + Meta CursorPaginationMeta `json:"meta"` + } + + tmp := opts + if tmp == nil { + tmp = &CBPOptions{} + } + + path := fmt.Sprintf("/groups/%d/users.json", tmp.Id) + u, err := addOptions(path, tmp) + + if err != nil { + return nil, data.Meta, err + } + + err = getData(z, ctx, u, &data) + if err != nil { + return nil, data.Meta, err + } + return data.Users, data.Meta, nil +} + diff --git a/zendesk/mock/client.go b/zendesk/mock/client.go index fe8720fb..985ee135 100644 --- a/zendesk/mock/client.go +++ b/zendesk/mock/client.go @@ -749,18 +749,18 @@ func (mr *ClientMockRecorder) GetBrand(ctx, brandID any) *gomock.Call { } // GetCountTicketsInViews mocks base method. -func (m *Client) GetCountTicketsInViews(arg0 context.Context, arg1 []string) ([]zendesk.ViewCount, error) { +func (m *Client) GetCountTicketsInViews(ctx context.Context, ids []string) ([]zendesk.ViewCount, error) { m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "GetCountTicketsInViews", arg0, arg1) + ret := m.ctrl.Call(m, "GetCountTicketsInViews", ctx, ids) ret0, _ := ret[0].([]zendesk.ViewCount) ret1, _ := ret[1].(error) return ret0, ret1 } // GetCountTicketsInViews indicates an expected call of GetCountTicketsInViews. -func (mr *ClientMockRecorder) GetCountTicketsInViews(arg0, arg1 interface{}) *gomock.Call { +func (mr *ClientMockRecorder) GetCountTicketsInViews(ctx, ids any) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetCountTicketsInViews", reflect.TypeOf((*Client)(nil).GetCountTicketsInViews), arg0, arg1) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetCountTicketsInViews", reflect.TypeOf((*Client)(nil).GetCountTicketsInViews), ctx, ids) } // GetCustomRoles mocks base method. @@ -932,6 +932,52 @@ func (mr *ClientMockRecorder) GetGroupMembershipsOBP(ctx, opts any) *gomock.Call return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetGroupMembershipsOBP", reflect.TypeOf((*Client)(nil).GetGroupMembershipsOBP), ctx, opts) } +// GetGroupUsersCBP mocks base method. +func (m *Client) GetGroupUsersCBP(ctx context.Context, opts *zendesk.CBPOptions) ([]zendesk.User, zendesk.CursorPaginationMeta, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "GetGroupUsersCBP", ctx, opts) + ret0, _ := ret[0].([]zendesk.User) + ret1, _ := ret[1].(zendesk.CursorPaginationMeta) + ret2, _ := ret[2].(error) + return ret0, ret1, ret2 +} + +// GetGroupUsersCBP indicates an expected call of GetGroupUsersCBP. +func (mr *ClientMockRecorder) GetGroupUsersCBP(ctx, opts any) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetGroupUsersCBP", reflect.TypeOf((*Client)(nil).GetGroupUsersCBP), ctx, opts) +} + +// GetGroupUsersIterator mocks base method. +func (m *Client) GetGroupUsersIterator(ctx context.Context, opts *zendesk.PaginationOptions) *zendesk.Iterator[zendesk.User] { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "GetGroupUsersIterator", ctx, opts) + ret0, _ := ret[0].(*zendesk.Iterator[zendesk.User]) + return ret0 +} + +// GetGroupUsersIterator indicates an expected call of GetGroupUsersIterator. +func (mr *ClientMockRecorder) GetGroupUsersIterator(ctx, opts any) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetGroupUsersIterator", reflect.TypeOf((*Client)(nil).GetGroupUsersIterator), ctx, opts) +} + +// GetGroupUsersOBP mocks base method. +func (m *Client) GetGroupUsersOBP(ctx context.Context, opts *zendesk.OBPOptions) ([]zendesk.User, zendesk.Page, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "GetGroupUsersOBP", ctx, opts) + ret0, _ := ret[0].([]zendesk.User) + ret1, _ := ret[1].(zendesk.Page) + ret2, _ := ret[2].(error) + return ret0, ret1, ret2 +} + +// GetGroupUsersOBP indicates an expected call of GetGroupUsersOBP. +func (mr *ClientMockRecorder) GetGroupUsersOBP(ctx, opts any) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetGroupUsersOBP", reflect.TypeOf((*Client)(nil).GetGroupUsersOBP), ctx, opts) +} + // GetGroups mocks base method. func (m *Client) GetGroups(ctx context.Context, opts *zendesk.GroupListOptions) ([]zendesk.Group, zendesk.Page, error) { m.ctrl.T.Helper() diff --git a/zendesk/user.go b/zendesk/user.go index 7dacf0e8..4a9ac5a8 100644 --- a/zendesk/user.go +++ b/zendesk/user.go @@ -128,6 +128,9 @@ type UserAPI interface { GetOrganizationUsersIterator(ctx context.Context, opts *PaginationOptions) *Iterator[User] GetOrganizationUsersOBP(ctx context.Context, opts *OBPOptions) ([]User, Page, error) GetOrganizationUsersCBP(ctx context.Context, opts *CBPOptions) ([]User, CursorPaginationMeta, error) + GetGroupUsersIterator(ctx context.Context, opts *PaginationOptions) *Iterator[User] + GetGroupUsersOBP(ctx context.Context, opts *OBPOptions) ([]User, Page, error) + GetGroupUsersCBP(ctx context.Context, opts *CBPOptions) ([]User, CursorPaginationMeta, error) } // GetUsers fetch user list