Skip to content

Commit

Permalink
add pagination to all users query - without pagination query doesn't …
Browse files Browse the repository at this point in the history
…return it time
  • Loading branch information
ilia-medvedev-codefresh committed May 27, 2024
1 parent 55e3ef2 commit 0263574
Showing 1 changed file with 32 additions and 16 deletions.
48 changes: 32 additions & 16 deletions codefresh/cfclient/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package cfclient

import (
"fmt"
"log"
//"log"
"strings"
)

Expand Down Expand Up @@ -222,25 +222,41 @@ func (client *Client) DeleteUserAsAccountAdmin(accountId, userId string) error {

func (client *Client) GetAllUsers() (*[]User, error) {

opts := RequestOptions{
Path: "/admin/user",
Method: "GET",
}
limitPerQuery := 100
bIsDone := false
nPageIndex := 1

resp, err := client.RequestAPI(&opts)
if err != nil {
return nil, err
}
var allUsers []User

var users []User
respStr := string(resp)
log.Printf("[INFO] GetAllUsers resp: %s", respStr)
err = DecodeResponseInto(resp, &users)
if err != nil {
return nil, err
for !bIsDone {
var userPaginatedResp struct{Docs []User `json:"docs"`}

opts := RequestOptions{
Path: fmt.Sprintf("/admin/user?limit=%d&page=%d", limitPerQuery, nPageIndex),
Method: "GET",
}

resp, err := client.RequestAPI(&opts)

if err != nil {
return nil, err
}

err = DecodeResponseInto(resp, &userPaginatedResp)

if err != nil {
return nil, err
}

if len(userPaginatedResp.Docs) > 0 {
allUsers = append(allUsers,userPaginatedResp.Docs...)
nPageIndex++
} else {
bIsDone = true
}
}

return &users, nil
return &allUsers, nil
}

func (client *Client) GetUserByID(userId string) (*User, error) {
Expand Down

0 comments on commit 0263574

Please sign in to comment.