Skip to content

Commit 08cf79d

Browse files
f0sselkylecarbs
authored andcommitted
fix: add workspace option 'deleted' to options type (#2095)
* fix: add workspace option 'deleted' to options type * dead code
1 parent d218d8c commit 08cf79d

File tree

5 files changed

+32
-23
lines changed

5 files changed

+32
-23
lines changed

coderd/workspaces.go

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -60,12 +60,6 @@ func (api *API) workspace(rw http.ResponseWriter, r *http.Request) {
6060
})
6161
return
6262
}
63-
if !workspace.Deleted && showDeleted {
64-
httpapi.Write(rw, http.StatusBadRequest, httpapi.Response{
65-
Message: fmt.Sprintf("Workspace %q is not deleted, please remove '?deleted=true' and try again", workspace.ID.String()),
66-
})
67-
return
68-
}
6963

7064
build, err := api.Database.GetLatestWorkspaceBuildByWorkspaceID(r.Context(), workspace.ID)
7165
if err != nil {

coderd/workspaces_test.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,9 @@ func TestWorkspace(t *testing.T) {
4646
workspace := coderdtest.CreateWorkspace(t, client, user.OrganizationID, template.ID)
4747
coderdtest.AwaitWorkspaceBuildJob(t, client, workspace.LatestBuild.ID)
4848

49-
// Getting with deleted=true should fail.
49+
// Getting with deleted=true should still work.
5050
_, err := client.DeletedWorkspace(context.Background(), workspace.ID)
51-
require.Error(t, err)
52-
require.ErrorContains(t, err, "400") // bad request
51+
require.NoError(t, err)
5352

5453
// Delete the workspace
5554
build, err := client.CreateWorkspaceBuild(context.Background(), workspace.ID, codersdk.CreateWorkspaceBuildRequest{

codersdk/client.go

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -36,14 +36,6 @@ type Client struct {
3636

3737
type requestOption func(*http.Request)
3838

39-
func queryParam(k, v string) requestOption {
40-
return func(r *http.Request) {
41-
q := r.URL.Query()
42-
q.Set(k, v)
43-
r.URL.RawQuery = q.Encode()
44-
}
45-
}
46-
4739
// Request performs an HTTP request with the body provided.
4840
// The caller is responsible for closing the response body.
4941
func (c *Client) Request(ctx context.Context, method, path string, body interface{}, opts ...requestOption) (*http.Response, error) {

codersdk/workspaces.go

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,14 +38,33 @@ type CreateWorkspaceBuildRequest struct {
3838
ProvisionerState []byte `json:"state,omitempty"`
3939
}
4040

41+
type WorkspaceOptions struct {
42+
Deleted bool `json:"deleted,omitempty"`
43+
}
44+
45+
// asRequestOption returns a function that can be used in (*Client).Request.
46+
// It modifies the request query parameters.
47+
func (o WorkspaceOptions) asRequestOption() requestOption {
48+
return func(r *http.Request) {
49+
q := r.URL.Query()
50+
if o.Deleted {
51+
q.Set("deleted", "true")
52+
}
53+
r.URL.RawQuery = q.Encode()
54+
}
55+
}
56+
4157
// Workspace returns a single workspace.
4258
func (c *Client) Workspace(ctx context.Context, id uuid.UUID) (Workspace, error) {
4359
return c.getWorkspace(ctx, id)
4460
}
4561

4662
// DeletedWorkspace returns a single workspace that was deleted.
4763
func (c *Client) DeletedWorkspace(ctx context.Context, id uuid.UUID) (Workspace, error) {
48-
return c.getWorkspace(ctx, id, queryParam("deleted", "true"))
64+
o := WorkspaceOptions{
65+
Deleted: true,
66+
}
67+
return c.getWorkspace(ctx, id, o.asRequestOption())
4968
}
5069

5170
func (c *Client) getWorkspace(ctx context.Context, id uuid.UUID, opts ...requestOption) (Workspace, error) {

site/src/api/typesGenerated.ts

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ export interface ProvisionerJobLog {
221221
readonly output: string
222222
}
223223

224-
// From codersdk/workspaces.go:182:6
224+
// From codersdk/workspaces.go:201:6
225225
export interface PutExtendWorkspaceRequest {
226226
readonly deadline: string
227227
}
@@ -298,12 +298,12 @@ export interface UpdateUserProfileRequest {
298298
readonly username: string
299299
}
300300

301-
// From codersdk/workspaces.go:141:6
301+
// From codersdk/workspaces.go:160:6
302302
export interface UpdateWorkspaceAutostartRequest {
303303
readonly schedule?: string
304304
}
305305

306-
// From codersdk/workspaces.go:161:6
306+
// From codersdk/workspaces.go:180:6
307307
export interface UpdateWorkspaceTTLRequest {
308308
readonly ttl_ms?: number
309309
}
@@ -445,18 +445,23 @@ export interface WorkspaceBuild {
445445
readonly deadline: string
446446
}
447447

448-
// From codersdk/workspaces.go:64:6
448+
// From codersdk/workspaces.go:83:6
449449
export interface WorkspaceBuildsRequest extends Pagination {
450450
readonly WorkspaceID: string
451451
}
452452

453-
// From codersdk/workspaces.go:200:6
453+
// From codersdk/workspaces.go:219:6
454454
export interface WorkspaceFilter {
455455
readonly organization_id?: string
456456
readonly owner?: string
457457
readonly name?: string
458458
}
459459

460+
// From codersdk/workspaces.go:41:6
461+
export interface WorkspaceOptions {
462+
readonly deleted?: boolean
463+
}
464+
460465
// From codersdk/workspaceresources.go:21:6
461466
export interface WorkspaceResource {
462467
readonly id: string

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy