Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

feat: getWorkspaces filter site api#1564

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
greyscaled merged 6 commits intomainfromvapurrmaid/gh-1552/getWorkspaces-filter
May 19, 2022
Merged
Show file tree
Hide file tree
Changes fromall commits
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
2 changes: 1 addition & 1 deletioncoderd/workspaces.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -151,7 +151,7 @@ func (api *api) workspaces(rw http.ResponseWriter, r *http.Request) {

// Empty strings mean no filter
orgFilter := r.URL.Query().Get("organization_id")
ownerFilter := r.URL.Query().Get("owner_id")
ownerFilter := r.URL.Query().Get("owner")

filter := database.GetWorkspacesWithFilterParams{Deleted: false}
if orgFilter != "" {
Expand Down
2 changes: 1 addition & 1 deletioncodersdk/workspaces.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -194,7 +194,7 @@ func (f WorkspaceFilter) asRequestOption() requestOption {
q.Set("organization_id", f.OrganizationID.String())
}
if f.Owner != "" {
q.Set("owner_id", f.Owner)
q.Set("owner", f.Owner)
}
r.URL.RawQuery = q.Encode()
}
Expand Down
15 changes: 14 additions & 1 deletionsite/src/api/api.test.ts
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
import axios from "axios"
import { getApiKey, login, logout } from "./api"
import { getApiKey,getWorkspacesURL,login, logout } from "./api"
import * as TypesGen from "./typesGenerated"

describe("api.ts", () => {
Expand DownExpand Up@@ -113,4 +113,17 @@ describe("api.ts", () => {
}
})
})

describe("getWorkspacesURL", () => {
it.each<[TypesGen.WorkspaceFilter | undefined, string]>([
[undefined, "/api/v2/workspaces"],

[{ OrganizationID: "1", Owner: "" }, "/api/v2/workspaces?organization_id=1"],
[{ OrganizationID: "", Owner: "1" }, "/api/v2/workspaces?owner=1"],

[{ OrganizationID: "1", Owner: "me" }, "/api/v2/workspaces?organization_id=1&owner=me"],
])(`getWorkspacesURL(%p) returns %p`, (filter, expected) => {
expect(getWorkspacesURL(filter)).toBe(expected)
})
})
})
23 changes: 19 additions & 4 deletionssite/src/api/api.ts
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -120,10 +120,25 @@ export const getWorkspace = async (workspaceId: string): Promise<TypesGen.Worksp
return response.data
}

// TODO: @emyrk add query params as arguments. Supports 'organization_id' and 'owner'
// 'owner' can be a username, user_id, or 'me'
export const getWorkspaces = async (): Promise<TypesGen.Workspace[]> => {
const response = await axios.get<TypesGen.Workspace[]>(`/api/v2/workspaces`)
export const getWorkspacesURL = (filter?: TypesGen.WorkspaceFilter): string => {
const basePath = "/api/v2/workspaces"
const searchParams = new URLSearchParams()

if (filter?.OrganizationID) {
searchParams.append("organization_id", filter.OrganizationID)
}
if (filter?.Owner) {
searchParams.append("owner", filter.Owner)
}

const searchString = searchParams.toString()

return searchString ? `${basePath}?${searchString}` : basePath
}

export const getWorkspaces = async (filter?: TypesGen.WorkspaceFilter): Promise<TypesGen.Workspace[]> => {
const url = getWorkspacesURL(filter)
const response = await axios.get<TypesGen.Workspace[]>(url)
return response.data
}

Expand Down
9 changes: 6 additions & 3 deletionssite/src/testHelpers/handlers.ts
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -36,9 +36,6 @@ export const handlers = [
rest.post("/api/v2/users/me/workspaces", async (req, res, ctx) => {
return res(ctx.status(200), ctx.json(M.MockWorkspace))
}),
rest.get("/api/v2/workspaces", async (req, res, ctx) => {
return res(ctx.status(200), ctx.json([M.MockWorkspace]))
}),
rest.get("/api/v2/users/me/organizations", (req, res, ctx) => {
return res(ctx.status(200), ctx.json([M.MockOrganization]))
}),
Expand DownExpand Up@@ -79,6 +76,12 @@ export const handlers = [
}),

// workspaces

// REMARK: This endpoint works with query parameters, but they won't be
// reflected in the return.
rest.get("/api/v2/workspaces", async (req, res, ctx) => {
return res(ctx.status(200), ctx.json([M.MockWorkspace]))
}),
rest.get("/api/v2/organizations/:organizationId/workspaces/:userName/:workspaceName", (req, res, ctx) => {
if (req.params.workspaceName !== M.MockWorkspace.name) {
return res(
Expand Down

[8]ページ先頭

©2009-2025 Movatter.jp