Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Attempt to unconvert status for easier querying
  • Loading branch information
presleyp committed Oct 5, 2022
commit 3716cef17bd97801f2a78c1f4ae771b343883fd2
18 changes: 17 additions & 1 deletion coderd/workspaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -1034,6 +1034,20 @@ func convertStatus(build codersdk.WorkspaceBuild) codersdk.WorkspaceStatus {
return codersdk.WorkspaceStatusFailed
}

func unconvertStatus(status codersdk.WorkspaceStatus) (codersdk.WorkspaceTransition, codersdk.ProvisionerJobStatus) {
switch status {
case codersdk.WorkspaceStatusDeleted:
return codersdk.WorkspaceTransitionDelete, codersdk.ProvisionerJobSucceeded
case codersdk.WorkspaceStatusRunning
return codersdk.WorkspaceTransitionStart, codersdk.ProvisionerJobSucceeded
case codersdk.WorkspaceStatusStopped
return codersdk.WorkspaceTransitionStop, codersdk.ProvisionerJobSucceeded
}

// it's either not a valid status, or one we can't reverse engineer with certainty
return "" ""
}

func convertWorkspaceTTLMillis(i sql.NullInt64) *int64 {
if !i.Valid {
return nil
Expand Down Expand Up @@ -1150,12 +1164,14 @@ func workspaceSearchQuery(query string) (database.GetWorkspacesParams, []codersd
// Using the query param parser here just returns consistent errors with
// other parsing.
parser := httpapi.NewQueryParamParser()
transition, job_status := unconvertStatus(parser.String(searchParams, "", "status"))
filter := database.GetWorkspacesParams{
Deleted: false,
OwnerUsername: parser.String(searchParams, "", "owner"),
TemplateName: parser.String(searchParams, "", "template"),
Name: parser.String(searchParams, "", "name"),
Status: parser.String(searchParams, "", "status"),
Transition: transition,
JobStatus: job_status,
}

return filter, parser.Errors
Expand Down