NOISSUE - Fix retrieving all users (#1477)

Signed-off-by: Burak Sekili <buraksekili@gmail.com>
This commit is contained in:
Burak Sekili 2021-10-18 18:00:15 +03:00 committed by GitHub
parent 5e9a91bd03
commit 042ff98509
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 30 additions and 19 deletions

View File

@ -169,19 +169,12 @@ func (ur userRepository) RetrieveAll(ctx context.Context, offset, limit uint64,
query = append(query, mq)
}
if len(userIDs) == 0 {
return users.UserPage{
Users: []users.User{},
PageMetadata: users.PageMetadata{
Total: 0,
Offset: offset,
Limit: limit,
},
}, nil
if len(userIDs) > 0 {
query = append(query, fmt.Sprintf("id IN ('%s')", strings.Join(userIDs, "','")))
}
if len(query) > 0 {
emq = fmt.Sprintf(" WHERE %s", strings.Join(query, " AND "))
}
query = append(query, fmt.Sprintf("id IN ('%s')", strings.Join(userIDs, "','")))
emq = fmt.Sprintf(" WHERE %s", strings.Join(query, " AND "))
q := fmt.Sprintf(`SELECT id, email, metadata FROM users %s ORDER BY email LIMIT :limit OFFSET :offset;`, emq)
params := map[string]interface{}{

View File

@ -201,13 +201,20 @@ func TestRetrieveAll(t *testing.T) {
metadata: meta,
},
"retrieve all users from empty ids": {
email: "All",
offset: 1,
limit: 5,
size: 0,
total: nUsers,
ids: []string{},
metadata: meta,
email: "All",
offset: 0,
limit: nUsers,
size: nUsers,
total: nUsers,
ids: []string{},
},
"retrieve all users from empty ids with offset": {
email: "All",
offset: 1,
limit: 5,
size: 5,
total: nUsers,
ids: []string{},
},
}
for desc, tc := range cases {

View File

@ -309,6 +309,17 @@ func (svc usersService) ListMembers(ctx context.Context, token, groupID string,
return UserPage{}, err
}
if len(userIDs) == 0 {
return UserPage{
Users: []User{},
PageMetadata: PageMetadata{
Total: 0,
Offset: offset,
Limit: limit,
},
}, nil
}
return svc.users.RetrieveAll(ctx, offset, limit, userIDs, "", m)
}