Fix workspace initialization

This commit is contained in:
2024-10-29 22:01:13 +01:00
parent 3ba9d57b11
commit a62a6f8966
3 changed files with 7 additions and 9 deletions

View File

@@ -16,7 +16,7 @@ func SetupRoutes(r chi.Router, db *db.DB, fs *filesystem.FileSystem) {
// Workspace routes // Workspace routes
r.Route("/workspaces", func(r chi.Router) { r.Route("/workspaces", func(r chi.Router) {
r.Get("/", ListWorkspaces(db)) r.Get("/", ListWorkspaces(db))
r.Post("/", CreateWorkspace(db)) r.Post("/", CreateWorkspace(db, fs))
r.Get("/last", GetLastWorkspace(db)) r.Get("/last", GetLastWorkspace(db))
r.Put("/last", UpdateLastWorkspace(db)) r.Put("/last", UpdateLastWorkspace(db))

View File

@@ -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) { return func(w http.ResponseWriter, r *http.Request) {
userID, err := getUserID(r) userID, err := getUserID(r)
if err != nil { if err != nil {
@@ -47,6 +47,11 @@ func CreateWorkspace(db *db.DB) http.HandlerFunc {
return 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) respondJSON(w, workspace)
} }
} }

View File

@@ -39,13 +39,6 @@ func (fs *FileSystem) InitializeUserWorkspace(userID, workspaceID int) error {
if err != nil { if err != nil {
return fmt.Errorf("failed to create workspace directory: %w", err) 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 return nil
} }