diff --git a/backend/internal/api/routes.go b/backend/internal/api/routes.go index af0b1f0..3682ca3 100644 --- a/backend/internal/api/routes.go +++ b/backend/internal/api/routes.go @@ -16,7 +16,7 @@ func SetupRoutes(r chi.Router, db *db.DB, fs *filesystem.FileSystem) { // Workspace routes r.Route("/workspaces", func(r chi.Router) { r.Get("/", ListWorkspaces(db)) - r.Post("/", CreateWorkspace(db)) + r.Post("/", CreateWorkspace(db, fs)) r.Get("/last", GetLastWorkspace(db)) r.Put("/last", UpdateLastWorkspace(db)) diff --git a/backend/internal/api/workspace_handlers.go b/backend/internal/api/workspace_handlers.go index c1c23c6..29415f5 100644 --- a/backend/internal/api/workspace_handlers.go +++ b/backend/internal/api/workspace_handlers.go @@ -27,7 +27,7 @@ func ListWorkspaces(db *db.DB) http.HandlerFunc { } } -func CreateWorkspace(db *db.DB) http.HandlerFunc { +func CreateWorkspace(db *db.DB, fs *filesystem.FileSystem) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { userID, err := getUserID(r) if err != nil { @@ -47,6 +47,11 @@ func CreateWorkspace(db *db.DB) http.HandlerFunc { return } + if err := fs.InitializeUserWorkspace(workspace.UserID, workspace.ID); err != nil { + http.Error(w, "Failed to initialize workspace directory", http.StatusInternalServerError) + return + } + respondJSON(w, workspace) } } diff --git a/backend/internal/filesystem/filesystem.go b/backend/internal/filesystem/filesystem.go index 6ecfaa0..38e29c1 100644 --- a/backend/internal/filesystem/filesystem.go +++ b/backend/internal/filesystem/filesystem.go @@ -39,13 +39,6 @@ func (fs *FileSystem) InitializeUserWorkspace(userID, workspaceID int) error { if err != nil { return fmt.Errorf("failed to create workspace directory: %w", err) } - // Optionally, create a welcome file in the new workspace - // welcomeFilePath := filepath.Join(workspacePath, "Welcome.md") - // welcomeContent := []byte("# Welcome to Your Main Workspace\n\nThis is your default workspace in NovaMD. You can start creating and editing files right away!") - // err = os.WriteFile(welcomeFilePath, welcomeContent, 0644) - // if err != nil { - // return fmt.Errorf("failed to create welcome file: %w", err) - // } return nil }