Skip to content

Commit

Permalink
Changed implementation of search in listmembers
Browse files Browse the repository at this point in the history
Signed-off-by: nyagamunene <[email protected]>
  • Loading branch information
nyagamunene authored and dborovcanin committed Aug 1, 2024
1 parent 0306536 commit 5e1eccf
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
Expand Up @@ -5,6 +5,7 @@ package users

import (
"context"
"strings"
"time"

"github.com/absmach/magistrala"
Expand Down Expand Up @@ -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)
Expand All @@ -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)

Expand Down

0 comments on commit 5e1eccf

Please sign in to comment.