chore: implement filters for the organizations query (#14468)

Required for organization sync. Allows fetching a filtered set of orgs.
This commit is contained in:
Steven Masley
2024-08-28 13:24:28 -05:00
committed by GitHub
parent 7667d64686
commit 54fe082551
13 changed files with 67 additions and 26 deletions
+15 -7
View File
@@ -3034,14 +3034,24 @@ func (q *FakeQuerier) GetOrganizationIDsByMemberIDs(_ context.Context, ids []uui
return getOrganizationIDsByMemberIDRows, nil
}
func (q *FakeQuerier) GetOrganizations(_ context.Context) ([]database.Organization, error) {
func (q *FakeQuerier) GetOrganizations(_ context.Context, args database.GetOrganizationsParams) ([]database.Organization, error) {
q.mutex.RLock()
defer q.mutex.RUnlock()
if len(q.organizations) == 0 {
return nil, sql.ErrNoRows
tmp := make([]database.Organization, 0)
for _, org := range q.organizations {
if len(args.IDs) > 0 {
if !slices.Contains(args.IDs, org.ID) {
continue
}
}
if args.Name != "" && !strings.EqualFold(org.Name, args.Name) {
continue
}
tmp = append(tmp, org)
}
return q.organizations, nil
return tmp, nil
}
func (q *FakeQuerier) GetOrganizationsByUserID(_ context.Context, userID uuid.UUID) ([]database.Organization, error) {
@@ -3060,9 +3070,7 @@ func (q *FakeQuerier) GetOrganizationsByUserID(_ context.Context, userID uuid.UU
organizations = append(organizations, organization)
}
}
if len(organizations) == 0 {
return nil, sql.ErrNoRows
}
return organizations, nil
}
+1 -1
View File
@@ -46,7 +46,7 @@ func TestInTx(t *testing.T) {
go func() {
<-inTx
for i := 0; i < 20; i++ {
orgs, err := uut.GetOrganizations(context.Background())
orgs, err := uut.GetOrganizations(context.Background(), database.GetOrganizationsParams{})
if err != nil {
assert.ErrorIs(t, err, sql.ErrNoRows)
}