NOISSUE - Fix retrieving all users (#1477)
Signed-off-by: Burak Sekili <buraksekili@gmail.com>
This commit is contained in:
parent
5e9a91bd03
commit
042ff98509
|
@ -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{}{
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue