GetWorkspaceByID gets a workspace by its resource ID. Returns (nil, nil) if not found.
(ctx context.Context, resourceID string)
| 55 | // GetWorkspaceByID gets a workspace by its resource ID. |
| 56 | // Returns (nil, nil) if not found. |
| 57 | func (s *Store) GetWorkspaceByID(ctx context.Context, resourceID string) (*WorkspaceMessage, error) { |
| 58 | var workspace WorkspaceMessage |
| 59 | var payloadBytes []byte |
| 60 | if err := s.GetDB().QueryRowContext(ctx, |
| 61 | `SELECT resource_id, payload FROM workspace WHERE resource_id = $1 AND deleted = FALSE`, |
| 62 | resourceID, |
| 63 | ).Scan(&workspace.ResourceID, &payloadBytes); err != nil { |
| 64 | if err == sql.ErrNoRows { |
| 65 | return nil, nil |
| 66 | } |
| 67 | return nil, errors.Wrap(err, "failed to get workspace") |
| 68 | } |
| 69 | payload := &storepb.WorkspacePayload{} |
| 70 | if err := common.ProtojsonUnmarshaler.Unmarshal(payloadBytes, payload); err != nil { |
| 71 | return nil, errors.Wrap(err, "failed to unmarshal workspace payload") |
| 72 | } |
| 73 | workspace.Payload = payload |
| 74 | return &workspace, nil |
| 75 | } |
| 76 | |
| 77 | // GetWorkspaceID returns the workspace resource ID. |
| 78 | // Returns ("", nil) if no workspace exists. |
no test coverage detected