| 149 | } |
| 150 | |
| 151 | func (s *Store) GetWorkspaceByID(id string) (*models.Workspace, error) { |
| 152 | var w models.Workspace |
| 153 | var createdAt, updatedAt string |
| 154 | var deletedAt *string |
| 155 | |
| 156 | err := s.db.QueryRow(s.q(` |
| 157 | SELECT w.id, w.name, w.slug, w.owner_id, COALESCE(ou.username, ''), w.description, w.settings, w.source, w.created_at, w.updated_at, w.deleted_at |
| 158 | FROM workspaces w |
| 159 | LEFT JOIN users ou ON ou.id = w.owner_id |
| 160 | WHERE w.id = ? AND w.deleted_at IS NULL |
| 161 | `), id).Scan(&w.ID, &w.Name, &w.Slug, &w.OwnerID, &w.OwnerUsername, &w.Description, &w.Settings, &w.Source, &createdAt, &updatedAt, &deletedAt) |
| 162 | if err == sql.ErrNoRows { |
| 163 | return nil, nil |
| 164 | } |
| 165 | if err != nil { |
| 166 | return nil, err |
| 167 | } |
| 168 | |
| 169 | w.CreatedAt = parseTime(createdAt) |
| 170 | w.UpdatedAt = parseTime(updatedAt) |
| 171 | w.DeletedAt = parseTimePtr(deletedAt) |
| 172 | w.HydrateDerivedFields() |
| 173 | return &w, nil |
| 174 | } |
| 175 | |
| 176 | // GetWorkspacesBySlugForUser finds workspaces matching a slug that are accessible |
| 177 | // to the given user (owned, member, or guest with grants). |