mirror of
https://github.com/coder/coder.git
synced 2026-06-02 20:48:20 +00:00
0672bf5084
## Description This PR adds support for `description` and `icon` fields to `template_version_presets`. These fields will allow displaying richer information for presets in the UI, improving the user experience when creating a workspace. Both fields are optional, non-nullable, and default to empty strings. ## Changes * Database migration with the addition of `description VARCHAR(128)` and `icon VARCHAR(256)` columns to the `template_version_presets` table. * Updated the `CreateWorkspacePageView` in the UI Note: UI changes will be addressed in a separate PR
41 lines
1022 B
Go
41 lines
1022 B
Go
package codersdk
|
|
|
|
import (
|
|
"context"
|
|
"encoding/json"
|
|
"fmt"
|
|
"net/http"
|
|
|
|
"github.com/google/uuid"
|
|
"golang.org/x/xerrors"
|
|
)
|
|
|
|
type Preset struct {
|
|
ID uuid.UUID
|
|
Name string
|
|
Parameters []PresetParameter
|
|
Default bool
|
|
DesiredPrebuildInstances *int
|
|
Description string
|
|
Icon string
|
|
}
|
|
|
|
type PresetParameter struct {
|
|
Name string
|
|
Value string
|
|
}
|
|
|
|
// TemplateVersionPresets returns the presets associated with a template version.
|
|
func (c *Client) TemplateVersionPresets(ctx context.Context, templateVersionID uuid.UUID) ([]Preset, error) {
|
|
res, err := c.Request(ctx, http.MethodGet, fmt.Sprintf("/api/v2/templateversions/%s/presets", templateVersionID), nil)
|
|
if err != nil {
|
|
return nil, xerrors.Errorf("do request: %w", err)
|
|
}
|
|
defer res.Body.Close()
|
|
if res.StatusCode != http.StatusOK {
|
|
return nil, ReadBodyAsError(res)
|
|
}
|
|
var presets []Preset
|
|
return presets, json.NewDecoder(res.Body).Decode(&presets)
|
|
}
|