From ffe82b335a16f901dc1ad9edcd0b111214f16021 Mon Sep 17 00:00:00 2001 From: LordMathis Date: Mon, 21 Oct 2024 23:48:50 +0200 Subject: [PATCH] Get full workspace object --- backend/internal/api/workspace_handlers.go | 2 +- backend/internal/db/workspace.go | 4 ++-- frontend/src/services/api.js | 9 ++++++++- 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/backend/internal/api/workspace_handlers.go b/backend/internal/api/workspace_handlers.go index 6ae8019..f9cbfc2 100644 --- a/backend/internal/api/workspace_handlers.go +++ b/backend/internal/api/workspace_handlers.go @@ -77,7 +77,7 @@ func GetWorkspace(db *db.DB) http.HandlerFunc { return } - respondJSON(w, map[string]string{"name": workspace.Name}) + respondJSON(w, workspace) } } diff --git a/backend/internal/db/workspace.go b/backend/internal/db/workspace.go index 1484e04..98cf07c 100644 --- a/backend/internal/db/workspace.go +++ b/backend/internal/db/workspace.go @@ -20,7 +20,7 @@ func (db *DB) CreateWorkspace(workspace *models.Workspace) error { func (db *DB) GetWorkspaceByID(id int) (*models.Workspace, error) { workspace := &models.Workspace{} - err := db.QueryRow("SELECT id, user_id, name, root_path, created_at FROM workspaces WHERE id = ?", id). + err := db.QueryRow("SELECT id, user_id, name, created_at FROM workspaces WHERE id = ?", id). Scan(&workspace.ID, &workspace.UserID, &workspace.Name, &workspace.CreatedAt) if err != nil { return nil, err @@ -29,7 +29,7 @@ func (db *DB) GetWorkspaceByID(id int) (*models.Workspace, error) { } func (db *DB) GetWorkspacesByUserID(userID int) ([]*models.Workspace, error) { - rows, err := db.Query("SELECT id, user_id, name, root_path, created_at FROM workspaces WHERE user_id = ?", userID) + rows, err := db.Query("SELECT id, user_id, name, created_at FROM workspaces WHERE user_id = ?", userID) if err != nil { return nil, err } diff --git a/frontend/src/services/api.js b/frontend/src/services/api.js index 66c1cad..892f73f 100644 --- a/frontend/src/services/api.js +++ b/frontend/src/services/api.js @@ -16,7 +16,7 @@ const apiCall = async (url, options = {}) => { } }; -export const fetchLastWorkspace = async () => { +export const fetchLastWorkspaceId = async () => { const response = await apiCall(`${API_BASE_URL}/users/1/workspaces/last`); return response.json(); }; @@ -59,6 +59,13 @@ export const deleteFile = async (workspaceId, filePath) => { return response.text(); }; +export const getWorkspace = async (workspaceId) => { + const response = await apiCall( + `${API_BASE_URL}/users/1/workspaces/${workspaceId}` + ); + return response.json(); +}; + export const fetchWorkspaceSettings = async (workspaceId) => { const response = await apiCall( `${API_BASE_URL}/users/1/workspaces/${workspaceId}/settings`