Returns updated workspace, whether it was updated, error.
(ctx context.Context, workspaceId string, name string, icon string, color string, applyDefaults bool)
| 77 | |
| 78 | // Returns updated workspace, whether it was updated, error. |
| 79 | func UpdateWorkspace(ctx context.Context, workspaceId string, name string, icon string, color string, applyDefaults bool) (*waveobj.Workspace, bool, error) { |
| 80 | ws, err := GetWorkspace(ctx, workspaceId) |
| 81 | updated := false |
| 82 | if err != nil { |
| 83 | return nil, updated, fmt.Errorf("workspace %s not found: %w", workspaceId, err) |
| 84 | } |
| 85 | if name != "" { |
| 86 | ws.Name = name |
| 87 | updated = true |
| 88 | } else if applyDefaults && ws.Name == "" { |
| 89 | ws.Name = fmt.Sprintf("New Workspace (%s)", ws.OID[0:5]) |
| 90 | updated = true |
| 91 | } |
| 92 | if icon != "" { |
| 93 | ws.Icon = icon |
| 94 | updated = true |
| 95 | } else if applyDefaults && ws.Icon == "" { |
| 96 | ws.Icon = WorkspaceIcons[0] |
| 97 | updated = true |
| 98 | } |
| 99 | if color != "" { |
| 100 | ws.Color = color |
| 101 | updated = true |
| 102 | } else if applyDefaults && ws.Color == "" { |
| 103 | wsList, err := ListWorkspaces(ctx) |
| 104 | if err != nil { |
| 105 | log.Printf("error listing workspaces: %v", err) |
| 106 | wsList = waveobj.WorkspaceList{} |
| 107 | } |
| 108 | ws.Color = WorkspaceColors[len(wsList)%len(WorkspaceColors)] |
| 109 | updated = true |
| 110 | } |
| 111 | if updated { |
| 112 | wstore.DBUpdate(ctx, ws) |
| 113 | } |
| 114 | return ws, updated, nil |
| 115 | } |
| 116 | |
| 117 | // If force is true, it will delete even if workspace is named. |
| 118 | // If workspace is empty, it will be deleted, even if it is named. |
no test coverage detected