mirror of
https://github.com/lordmathis/lemma.git
synced 2025-11-06 16:04:23 +00:00
Fix workspace initialization
This commit is contained in:
@@ -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))
|
||||||
|
|
||||||
|
|||||||
@@ -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)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user