Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Changed implementation of search in listmembers
Browse files Browse the repository at this point in the history
Signed-off-by: nyagamunene <[email protected]>
nyagamunene committed Aug 1, 2024
1 parent 38386a3 commit 3dccd99
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions users/service.go
Original file line number Diff line number Diff line change
@@ -5,6 +5,7 @@ package users

import (
"context"
"strings"
"time"

"github.com/absmach/magistrala"
@@ -523,6 +524,11 @@ func (svc service) ListMembers(ctx context.Context, token, objectKind, objectID
}
pm.IDs = userIDs

var nameQuery string
if pm.Name != "" && len(pm.IDs) != 0 {
nameQuery = pm.Name
pm.Name = ""
}
cp, err := svc.clients.RetrieveAll(ctx, pm)
if err != nil {
return mgclients.MembersPage{}, errors.Wrap(svcerr.ErrViewEntity, err)
@@ -538,6 +544,16 @@ func (svc service) ListMembers(ctx context.Context, token, objectKind, objectID
}
}

if nameQuery != "" {
filteredClients := make([]mgclients.Client, 0, len(cp.Clients))
for _, c := range cp.Clients {
if strings.Contains(c.Name, nameQuery) {
filteredClients = append(filteredClients, c)
}
}
cp.Clients = filteredClients
}

if pm.ListPerms && len(cp.Clients) > 0 {
g, ctx := errgroup.WithContext(ctx)

0 comments on commit 3dccd99

Please sign in to comment.