chore: add group_ids filter to /groups endpoint (#14688)

Allow filtering groups by IDs.
This commit is contained in:
Steven Masley
2024-09-16 13:01:46 -05:00
committed by GitHub
parent 5ed065d88d
commit c330af0e4d
10 changed files with 99 additions and 9 deletions
+6
View File
@@ -2714,6 +2714,12 @@ func (q *FakeQuerier) GetGroups(_ context.Context, arg database.GetGroupsParams)
orgDetailsCache := make(map[uuid.UUID]struct{ name, displayName string })
filtered := make([]database.GetGroupsRow, 0)
for _, group := range q.groups {
if len(arg.GroupIds) > 0 {
if !slices.Contains(arg.GroupIds, group.ID) {
continue
}
}
if arg.OrganizationID != uuid.Nil && group.OrganizationID != arg.OrganizationID {
continue
}
+14 -4
View File
@@ -1683,12 +1683,17 @@ WHERE
groups.name = ANY($3)
ELSE true
END
AND CASE WHEN array_length($4 :: uuid[], 1) > 0 THEN
groups.id = ANY($4)
ELSE true
END
`
type GetGroupsParams struct {
OrganizationID uuid.UUID `db:"organization_id" json:"organization_id"`
HasMemberID uuid.UUID `db:"has_member_id" json:"has_member_id"`
GroupNames []string `db:"group_names" json:"group_names"`
OrganizationID uuid.UUID `db:"organization_id" json:"organization_id"`
HasMemberID uuid.UUID `db:"has_member_id" json:"has_member_id"`
GroupNames []string `db:"group_names" json:"group_names"`
GroupIds []uuid.UUID `db:"group_ids" json:"group_ids"`
}
type GetGroupsRow struct {
@@ -1698,7 +1703,12 @@ type GetGroupsRow struct {
}
func (q *sqlQuerier) GetGroups(ctx context.Context, arg GetGroupsParams) ([]GetGroupsRow, error) {
rows, err := q.db.QueryContext(ctx, getGroups, arg.OrganizationID, arg.HasMemberID, pq.Array(arg.GroupNames))
rows, err := q.db.QueryContext(ctx, getGroups,
arg.OrganizationID,
arg.HasMemberID,
pq.Array(arg.GroupNames),
pq.Array(arg.GroupIds),
)
if err != nil {
return nil, err
}
+4
View File
@@ -56,6 +56,10 @@ WHERE
groups.name = ANY(@group_names)
ELSE true
END
AND CASE WHEN array_length(@group_ids :: uuid[], 1) > 0 THEN
groups.id = ANY(@group_ids)
ELSE true
END
;
-- name: InsertGroup :one