MCPcopy Create free account
hub / github.com/PerpetualSoftware/pad / UpdateWorkspace

Method UpdateWorkspace

internal/store/workspaces.go:216–260  ·  view source on GitHub ↗
(slug string, input models.WorkspaceUpdate)

Source from the content-addressed store, hash-verified

214}
215
216func (s *Store) UpdateWorkspace(slug string, input models.WorkspaceUpdate) (*models.Workspace, error) {
217 w, err := s.GetWorkspaceBySlug(slug)
218 if err != nil {
219 return nil, err
220 }
221 if w == nil {
222 return nil, nil
223 }
224
225 ts := now()
226
227 if input.Name != nil {
228 w.Name = *input.Name
229 }
230 if input.Description != nil {
231 w.Description = *input.Description
232 }
233 if input.Settings != nil {
234 w.Settings = *input.Settings
235 }
236 if input.Context != nil {
237 settings, err := models.ApplyWorkspaceContext(w.Settings, input.Context)
238 if err != nil {
239 return nil, fmt.Errorf("apply workspace context: %w", err)
240 }
241 w.Settings = settings
242 }
243 if w.Settings != "" {
244 settings, err := models.NormalizeWorkspaceSettings(w.Settings)
245 if err != nil {
246 return nil, fmt.Errorf("normalize workspace settings: %w", err)
247 }
248 w.Settings = settings
249 }
250
251 _, err = s.db.Exec(s.q(`
252 UPDATE workspaces SET name = ?, description = ?, settings = ?, updated_at = ?
253 WHERE id = ?
254 `), w.Name, w.Description, w.Settings, ts, w.ID)
255 if err != nil {
256 return nil, err
257 }
258
259 return s.GetWorkspaceBySlug(slug)
260}
261
262func (s *Store) DeleteWorkspace(slug string) error {
263 ts := now()

Callers 2

TestWorkspaceCRUDFunction · 0.45
handleUpdateWorkspaceMethod · 0.45

Calls 6

GetWorkspaceBySlugMethod · 0.95
qMethod · 0.95
ApplyWorkspaceContextFunction · 0.92
ExecMethod · 0.80
nowFunction · 0.70

Tested by 1

TestWorkspaceCRUDFunction · 0.36