- Notifications
You must be signed in to change notification settings - Fork1k
feat(coderd): add support for presets to the coder API#16526
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Changes fromall commits
dcf47ab
e4b5f0d
212e536
2579887
341c2b4
4fa6674
c31ee7b
ce2956d
63b5770
ce013a5
22eb048
af4eb7f
File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more abouthow customized files appear on GitHub.
Uh oh!
There was an error while loading.Please reload this page.
Some generated files are not rendered by default. Learn more abouthow customized files appear on GitHub.
Uh oh!
There was an error while loading.Please reload this page.
Some generated files are not rendered by default. Learn more abouthow customized files appear on GitHub.
Uh oh!
There was an error while loading.Please reload this page.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
ALTER TABLE template_version_presets | ||
ALTER COLUMN id DROP DEFAULT; | ||
ALTER TABLE template_version_preset_parameters | ||
ALTER COLUMN id DROP DEFAULT; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
ALTER TABLE template_version_presets | ||
ALTER COLUMN id SET DEFAULT gen_random_uuid(); | ||
ALTER TABLE template_version_preset_parameters | ||
ALTER COLUMN id SET DEFAULT gen_random_uuid(); | ||
SasSwart marked this conversation as resolved. Show resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. |
Some generated files are not rendered by default. Learn more abouthow customized files appear on GitHub.
Uh oh!
There was an error while loading.Please reload this page.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
package coderd | ||
import ( | ||
"net/http" | ||
"github.com/coder/coder/v2/coderd/httpapi" | ||
"github.com/coder/coder/v2/coderd/httpmw" | ||
"github.com/coder/coder/v2/codersdk" | ||
) | ||
// @Summary Get template version presets | ||
// @ID get-template-version-presets | ||
// @Security CoderSessionToken | ||
// @Produce json | ||
// @Tags Templates | ||
// @Param templateversion path string true "Template version ID" format(uuid) | ||
// @Success 200 {array} codersdk.Preset | ||
// @Router /templateversions/{templateversion}/presets [get] | ||
func (api *API) templateVersionPresets(rw http.ResponseWriter, r *http.Request) { | ||
ctx := r.Context() | ||
templateVersion := httpmw.TemplateVersionParam(r) | ||
presets, err := api.Database.GetPresetsByTemplateVersionID(ctx, templateVersion.ID) | ||
if err != nil { | ||
httpapi.Write(ctx, rw, http.StatusInternalServerError, codersdk.Response{ | ||
Message: "Internal error fetching template version presets.", | ||
Detail: err.Error(), | ||
}) | ||
return | ||
} | ||
presetParams, err := api.Database.GetPresetParametersByTemplateVersionID(ctx, templateVersion.ID) | ||
if err != nil { | ||
httpapi.Write(ctx, rw, http.StatusInternalServerError, codersdk.Response{ | ||
Message: "Internal error fetching template version presets.", | ||
Detail: err.Error(), | ||
}) | ||
return | ||
} | ||
var res []codersdk.Preset | ||
for _, preset := range presets { | ||
sdkPreset := codersdk.Preset{ | ||
ID: preset.ID, | ||
Name: preset.Name, | ||
} | ||
for _, presetParam := range presetParams { | ||
sdkPreset.Parameters = append(sdkPreset.Parameters, codersdk.PresetParameter{ | ||
Name: presetParam.Name, | ||
Value: presetParam.Value, | ||
}) | ||
} | ||
res = append(res, sdkPreset) | ||
} | ||
httpapi.Write(ctx, rw, http.StatusOK, res) | ||
} |
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.