diff --git a/client/environment.go b/client/environment.go index fbf67859..b6b61774 100644 --- a/client/environment.go +++ b/client/environment.go @@ -233,24 +233,20 @@ type EnvironmentDeployResponse struct { Id string `json:"id"` } -func (Environment) getEndpoint() string { - return "/environments" -} - func (client *ApiClient) EnvironmentsByName(name string) ([]Environment, error) { organizationId, err := client.OrganizationId() if err != nil { return nil, err } - return getAll(client, map[string]string{ + return getAll[Environment](client, "/environments", map[string]string{ "organizationId": organizationId, "name": name, }) } func (client *ApiClient) ProjectEnvironments(projectId string) ([]Environment, error) { - return getAll(client, map[string]string{ + return getAll[Environment](client, "/environments", map[string]string{ "projectId": projectId, }) } diff --git a/client/pagination.go b/client/pagination.go index b2869049..5c1b798a 100644 --- a/client/pagination.go +++ b/client/pagination.go @@ -9,11 +9,6 @@ type Pagination struct { params map[string]string } -type Paginated interface { - Environment - getEndpoint() string -} - func (p *Pagination) getParams() map[string]string { return map[string]string{ "limit": strconv.Itoa(limit), @@ -29,7 +24,7 @@ func (p *Pagination) next(currentPageSize int) bool { } // params - additional params. may be nil. -func getAll[P Paginated](client *ApiClient, params map[string]string) ([]P, error) { +func getAll[P any](client *ApiClient, endpoint string, params map[string]string) ([]P, error) { p := Pagination{ offset: 0, params: params, @@ -45,7 +40,7 @@ func getAll[P Paginated](client *ApiClient, params map[string]string) ([]P, erro var pageResults []P - err := client.http.Get(P{}.getEndpoint(), pageParams, &pageResults) + err := client.http.Get(endpoint, pageParams, &pageResults) if err != nil { return nil, err } diff --git a/client/team.go b/client/team.go index 64189843..f329303f 100644 --- a/client/team.go +++ b/client/team.go @@ -84,14 +84,9 @@ func (client *ApiClient) GetTeams(params map[string]string) ([]Team, error) { return nil, err } - var result []Team + endpoint := "/teams/organizations/" + organizationId - err = client.http.Get("/teams/organizations/"+organizationId, params, &result) - if err != nil { - return nil, err - } - - return result, err + return getAll[Team](client, endpoint, params) } func (client *ApiClient) Teams() ([]Team, error) { diff --git a/client/team_test.go b/client/team_test.go index 7890a9be..0ec3c96a 100644 --- a/client/team_test.go +++ b/client/team_test.go @@ -44,7 +44,10 @@ var _ = Describe("Teams Client", func() { BeforeEach(func() { mockOrganizationIdCall() httpCall = mockHttpClient.EXPECT(). - Get("/teams/organizations/"+organizationId, nil, gomock.Any()). + Get("/teams/organizations/"+organizationId, map[string]string{ + "offset": "0", + "limit": "100", + }, gomock.Any()). Do(func(path string, request interface{}, response *[]Team) { *response = mockTeams })