feat: scaffold codespace backend
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,36 @@
|
||||
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)
|
||||
}
|
||||
Reference in New Issue
Block a user