37 lines
1009 B
Go
37 lines
1009 B
Go
package service
|
|
|
|
import (
|
|
"codespace/internal/process"
|
|
"codespace/internal/workspace"
|
|
)
|
|
|
|
// WorkspaceService orchestrates workspace lifecycle operations.
|
|
type WorkspaceService struct {
|
|
workspaces workspace.Manager
|
|
processes process.Manager
|
|
}
|
|
|
|
// NewWorkspaceService creates a WorkspaceService.
|
|
func NewWorkspaceService(workspaces workspace.Manager, processes process.Manager) *WorkspaceService {
|
|
return &WorkspaceService{workspaces: workspaces, processes: processes}
|
|
}
|
|
|
|
// Create creates a new workspace.
|
|
func (s *WorkspaceService) Create(id string) (*workspace.Workspace, error) {
|
|
return s.workspaces.Create(id)
|
|
}
|
|
|
|
// Get retrieves a workspace by id.
|
|
func (s *WorkspaceService) Get(id string) (*workspace.Workspace, error) {
|
|
return s.workspaces.Get(id)
|
|
}
|
|
|
|
// Delete stops any running process for the workspace, then removes it.
|
|
func (s *WorkspaceService) Delete(id string) error {
|
|
status := s.processes.Status(id)
|
|
if status.Running {
|
|
_ = s.processes.Stop(id)
|
|
}
|
|
return s.workspaces.Delete(id)
|
|
}
|