From 4175f2cf3fe6a17f89158d2c31807485fd73d589 Mon Sep 17 00:00:00 2001 From: Lanre Adelowo Date: Sat, 1 Feb 2025 00:20:48 +0100 Subject: [PATCH] update url for switching a workspace --- server/http.go | 2 +- server/middleware.go | 1 + server/workspace.go | 2 +- swagger/docs.go | 112 +++++++++++++++--------------- swagger/swagger.json | 144 +++++++++++++++++++-------------------- swagger/swagger.yaml | 64 ++++++++--------- web/ui/src/client/Api.ts | 32 ++++----- 7 files changed, 179 insertions(+), 178 deletions(-) diff --git a/server/http.go b/server/http.go index eef3be30..6832c368 100644 --- a/server/http.go +++ b/server/http.go @@ -235,7 +235,7 @@ func buildRoutes( r.Post("/billing", WrapMalakHTTPHandler(logger, workspaceHandler.getBillingPortal, cfg, "workspaces.billing.portal")) - r.Post("/{reference}", + r.Post("/switch/{reference}", WrapMalakHTTPHandler(logger, workspaceHandler.switchCurrentWorkspaceForUser, cfg, "workspaces.switch")) r.Route("/integrations", func(r chi.Router) { diff --git a/server/middleware.go b/server/middleware.go index 24a579c1..b692dfcd 100644 --- a/server/middleware.go +++ b/server/middleware.go @@ -88,6 +88,7 @@ func requireWorkspaceValidSubscription( defer span.End() if r.URL.Path == "/v1/workspaces/billing" || + strings.HasPrefix(r.URL.Path, "/v1/workspaces/switch/") || r.URL.Path == "/v1/workspaces" || r.URL.Path == "/v1/user" { next.ServeHTTP(w, r) diff --git a/server/workspace.go b/server/workspace.go index 5d01fb32..e494c7f3 100644 --- a/server/workspace.go +++ b/server/workspace.go @@ -143,7 +143,7 @@ func (wo *workspaceHandler) createWorkspace( // @Failure 401 {object} APIStatus // @Failure 404 {object} APIStatus // @Failure 500 {object} APIStatus -// @Router /workspaces/{reference} [post] +// @Router /workspaces/switch/{reference} [post] func (wo *workspaceHandler) switchCurrentWorkspaceForUser( ctx context.Context, span trace.Span, diff --git a/swagger/docs.go b/swagger/docs.go index 675ece32..ba5e6c37 100644 --- a/swagger/docs.go +++ b/swagger/docs.go @@ -1510,6 +1510,62 @@ const docTemplate = `{ } } }, + "/workspaces/switch/{reference}": { + "post": { + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "workspace" + ], + "summary": "Switch current workspace", + "operationId": "switchworkspace", + "parameters": [ + { + "type": "string", + "description": "Workspace unique reference.. e.g update_", + "name": "reference", + "in": "path", + "required": true + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/server.fetchWorkspaceResponse" + } + }, + "400": { + "description": "Bad Request", + "schema": { + "$ref": "#/definitions/server.APIStatus" + } + }, + "401": { + "description": "Unauthorized", + "schema": { + "$ref": "#/definitions/server.APIStatus" + } + }, + "404": { + "description": "Not Found", + "schema": { + "$ref": "#/definitions/server.APIStatus" + } + }, + "500": { + "description": "Internal Server Error", + "schema": { + "$ref": "#/definitions/server.APIStatus" + } + } + } + } + }, "/workspaces/updates": { "get": { "consumes": [ @@ -2145,62 +2201,6 @@ const docTemplate = `{ } } } - }, - "/workspaces/{reference}": { - "post": { - "consumes": [ - "application/json" - ], - "produces": [ - "application/json" - ], - "tags": [ - "workspace" - ], - "summary": "Switch current workspace", - "operationId": "switchworkspace", - "parameters": [ - { - "type": "string", - "description": "Workspace unique reference.. e.g update_", - "name": "reference", - "in": "path", - "required": true - } - ], - "responses": { - "200": { - "description": "OK", - "schema": { - "$ref": "#/definitions/server.fetchWorkspaceResponse" - } - }, - "400": { - "description": "Bad Request", - "schema": { - "$ref": "#/definitions/server.APIStatus" - } - }, - "401": { - "description": "Unauthorized", - "schema": { - "$ref": "#/definitions/server.APIStatus" - } - }, - "404": { - "description": "Not Found", - "schema": { - "$ref": "#/definitions/server.APIStatus" - } - }, - "500": { - "description": "Internal Server Error", - "schema": { - "$ref": "#/definitions/server.APIStatus" - } - } - } - } } }, "definitions": { diff --git a/swagger/swagger.json b/swagger/swagger.json index 6be254c5..8731d884 100644 --- a/swagger/swagger.json +++ b/swagger/swagger.json @@ -3344,6 +3344,78 @@ ] } }, + "/workspaces/switch/{reference}": { + "post": { + "operationId": "switchworkspace", + "parameters": [ + { + "description": "Workspace unique reference.. e.g update_", + "in": "path", + "name": "reference", + "required": true, + "schema": { + "type": "string" + } + } + ], + "responses": { + "200": { + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/server.fetchWorkspaceResponse" + } + } + }, + "description": "OK" + }, + "400": { + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/server.APIStatus" + } + } + }, + "description": "Bad Request" + }, + "401": { + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/server.APIStatus" + } + } + }, + "description": "Unauthorized" + }, + "404": { + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/server.APIStatus" + } + } + }, + "description": "Not Found" + }, + "500": { + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/server.APIStatus" + } + } + }, + "description": "Internal Server Error" + } + }, + "summary": "Switch current workspace", + "tags": [ + "workspace" + ] + } + }, "/workspaces/updates": { "get": { "parameters": [ @@ -4165,78 +4237,6 @@ "updates" ] } - }, - "/workspaces/{reference}": { - "post": { - "operationId": "switchworkspace", - "parameters": [ - { - "description": "Workspace unique reference.. e.g update_", - "in": "path", - "name": "reference", - "required": true, - "schema": { - "type": "string" - } - } - ], - "responses": { - "200": { - "content": { - "application/json": { - "schema": { - "$ref": "#/components/schemas/server.fetchWorkspaceResponse" - } - } - }, - "description": "OK" - }, - "400": { - "content": { - "application/json": { - "schema": { - "$ref": "#/components/schemas/server.APIStatus" - } - } - }, - "description": "Bad Request" - }, - "401": { - "content": { - "application/json": { - "schema": { - "$ref": "#/components/schemas/server.APIStatus" - } - } - }, - "description": "Unauthorized" - }, - "404": { - "content": { - "application/json": { - "schema": { - "$ref": "#/components/schemas/server.APIStatus" - } - } - }, - "description": "Not Found" - }, - "500": { - "content": { - "application/json": { - "schema": { - "$ref": "#/components/schemas/server.APIStatus" - } - } - }, - "description": "Internal Server Error" - } - }, - "summary": "Switch current workspace", - "tags": [ - "workspace" - ] - } } }, "servers": [ diff --git a/swagger/swagger.yaml b/swagger/swagger.yaml index b7002f03..0b7d3d6d 100644 --- a/swagger/swagger.yaml +++ b/swagger/swagger.yaml @@ -1985,22 +1985,14 @@ paths: summary: Create a new workspace tags: - workspace - /workspaces/{reference}: + /workspaces/billing: post: - operationId: switchworkspace - parameters: - - description: Workspace unique reference.. e.g update_ - in: path - name: reference - required: true - schema: - type: string responses: "200": content: application/json: schema: - $ref: '#/components/schemas/server.fetchWorkspaceResponse' + $ref: '#/components/schemas/server.fetchBillingPortalResponse' description: OK "400": content: @@ -2026,17 +2018,17 @@ paths: schema: $ref: '#/components/schemas/server.APIStatus' description: Internal Server Error - summary: Switch current workspace + summary: get billing portal tags: - - workspace - /workspaces/billing: - post: + - billing + /workspaces/integrations: + get: responses: "200": content: application/json: schema: - $ref: '#/components/schemas/server.fetchBillingPortalResponse' + $ref: '#/components/schemas/server.listIntegrationResponse' description: OK "400": content: @@ -2062,17 +2054,17 @@ paths: schema: $ref: '#/components/schemas/server.APIStatus' description: Internal Server Error - summary: get billing portal + summary: fetch workspace preferences tags: - - billing - /workspaces/integrations: + - workspace + /workspaces/preferences: get: responses: "200": content: application/json: schema: - $ref: '#/components/schemas/server.listIntegrationResponse' + $ref: '#/components/schemas/server.preferenceResponse' description: OK "400": content: @@ -2101,8 +2093,15 @@ paths: summary: fetch workspace preferences tags: - workspace - /workspaces/preferences: - get: + put: + requestBody: + content: + application/json: + schema: + $ref: '#/components/schemas/server.updatePreferencesRequest' + description: request body to updare a workspace preference + required: true + x-originalParamName: message responses: "200": content: @@ -2134,24 +2133,25 @@ paths: schema: $ref: '#/components/schemas/server.APIStatus' description: Internal Server Error - summary: fetch workspace preferences + summary: update workspace preferences tags: - workspace - put: - requestBody: - content: - application/json: - schema: - $ref: '#/components/schemas/server.updatePreferencesRequest' - description: request body to updare a workspace preference + /workspaces/switch/{reference}: + post: + operationId: switchworkspace + parameters: + - description: Workspace unique reference.. e.g update_ + in: path + name: reference required: true - x-originalParamName: message + schema: + type: string responses: "200": content: application/json: schema: - $ref: '#/components/schemas/server.preferenceResponse' + $ref: '#/components/schemas/server.fetchWorkspaceResponse' description: OK "400": content: @@ -2177,7 +2177,7 @@ paths: schema: $ref: '#/components/schemas/server.APIStatus' description: Internal Server Error - summary: update workspace preferences + summary: Switch current workspace tags: - workspace /workspaces/updates: diff --git a/web/ui/src/client/Api.ts b/web/ui/src/client/Api.ts index 6ec3aeec..c256cecb 100644 --- a/web/ui/src/client/Api.ts +++ b/web/ui/src/client/Api.ts @@ -1117,22 +1117,6 @@ export class Api extends HttpClient - this.request({ - path: `/workspaces/${reference}`, - method: "POST", - format: "json", - ...params, - }), - /** * No description * @@ -1199,6 +1183,22 @@ export class Api extends HttpClient + this.request({ + path: `/workspaces/switch/${reference}`, + method: "POST", + format: "json", + ...params, + }), + /** * No description *