feat: Workspaces filtering (#1972)

Co-authored-by: G r e y <grey@coder.com>
Co-authored-by: Kira Pilot <kira@coder.com>
This commit is contained in:
Garrett Delfosse
2022-06-03 17:20:28 +00:00
committed by GitHub
co-authored by G r e y Kira Pilot
parent ac6cb269db
commit 8b03e2b0e1
14 changed files with 377 additions and 121 deletions
@@ -328,6 +328,9 @@ func (q *fakeQuerier) GetWorkspacesWithFilter(_ context.Context, arg database.Ge
if !arg.Deleted && workspace.Deleted {
continue
}
if arg.Name != "" && workspace.Name != arg.Name {
continue
}
workspaces = append(workspaces, workspace)
}
+13 -1
View File
@@ -3509,16 +3509,28 @@ WHERE
owner_id = $3
ELSE true
END
-- Filter by name
AND CASE
WHEN $4 :: text != '' THEN
LOWER(name) = LOWER($4)
ELSE true
END
`
type GetWorkspacesWithFilterParams struct {
Deleted bool `db:"deleted" json:"deleted"`
OrganizationID uuid.UUID `db:"organization_id" json:"organization_id"`
OwnerID uuid.UUID `db:"owner_id" json:"owner_id"`
Name string `db:"name" json:"name"`
}
func (q *sqlQuerier) GetWorkspacesWithFilter(ctx context.Context, arg GetWorkspacesWithFilterParams) ([]Workspace, error) {
rows, err := q.db.QueryContext(ctx, getWorkspacesWithFilter, arg.Deleted, arg.OrganizationID, arg.OwnerID)
rows, err := q.db.QueryContext(ctx, getWorkspacesWithFilter,
arg.Deleted,
arg.OrganizationID,
arg.OwnerID,
arg.Name,
)
if err != nil {
return nil, err
}
+6
View File
@@ -28,6 +28,12 @@ WHERE
owner_id = @owner_id
ELSE true
END
-- Filter by name
AND CASE
WHEN @name :: text != '' THEN
LOWER(name) = LOWER(@name)
ELSE true
END
;
-- name: GetWorkspacesByOrganizationIDs :many