feat: add paginated API endpoint for groups (#27603)

backend-only changes from #27271; see that PR for summary of changes +
implementation details
This commit is contained in:
Andrew Aquino
2026-08-10 13:23:14 -07:00
committed by GitHub
parent ddb2799009
commit 6e07e2610f
19 changed files with 1189 additions and 0 deletions
+38
View File
@@ -91,6 +91,44 @@ WHERE
LIMIT NULLIF(@limit_opt :: int, 0)
;
-- name: GetGroupsByOrganizationIDPaginated :many
SELECT
sqlc.embed(groups),
organizations.name AS organization_name,
organizations.display_name AS organization_display_name,
COUNT(*) OVER() AS count
FROM
groups
INNER JOIN
organizations ON groups.organization_id = organizations.id
WHERE
true
AND groups.organization_id = @organization_id
-- Keyset pagination cursor. When @after_id is set, return only groups
-- ordered after it, matching the ORDER BY (LOWER(name), id) below. This
-- lets callers page without duplicated or skipped rows even if groups are
-- inserted or deleted between page requests.
AND CASE
WHEN @after_id :: uuid != '00000000-0000-0000-0000-000000000000' :: uuid THEN
(LOWER(groups.name), groups.id) > (
SELECT LOWER(name), id FROM groups WHERE id = @after_id
)
ELSE true
END
-- Filter by group name or display name (substring, case-insensitive).
AND CASE WHEN @search :: text != '' THEN (
groups.name ILIKE concat('%', @search, '%')
OR groups.display_name ILIKE concat('%', @search, '%')
)
ELSE true
END
ORDER BY
-- Deterministic and consistent ordering of all groups. This is to ensure consistent pagination.
LOWER(groups.name) ASC, groups.id ASC OFFSET @offset_opt
LIMIT
-- A null limit means "no limit", so 0 means return all
NULLIF(@limit_opt :: int, 0);
-- name: InsertGroup :one
INSERT INTO groups (
id,