- Notifications
You must be signed in to change notification settings - Fork928
feat(coder): Add PATCH /templateversions/:templateversion endpoint#6698
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
f5bf8f9
73aa2dd
7a39d34
7be61cd
1d34942
7d0b0c9
a480655
aca5131
9b35142
e5d6642
41bc1dd
c792dca
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.
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 |
---|---|---|
@@ -63,6 +63,66 @@ func (api *API) templateVersion(rw http.ResponseWriter, r *http.Request) { | ||
httpapi.Write(ctx, rw, http.StatusOK, convertTemplateVersion(templateVersion, convertProvisionerJob(job), user)) | ||
} | ||
// @Summary Patch template version by ID | ||
// @ID patch-template-version-by-id | ||
// @Security CoderSessionToken | ||
// @Accept json | ||
// @Produce json | ||
// @Tags Templates | ||
// @Param templateversion path string true "Template version ID" format(uuid) | ||
// @Param request body codersdk.PatchTemplateVersionRequest true "Patch template version request" | ||
// @Success 200 {object} codersdk.TemplateVersion | ||
// @Router /templateversions/{templateversion} [patch] | ||
func (api *API) patchTemplateVersion(rw http.ResponseWriter, r *http.Request) { | ||
ctx := r.Context() | ||
templateVersion := httpmw.TemplateVersionParam(r) | ||
var params codersdk.PatchTemplateVersionRequest | ||
BrunoQuaresma marked this conversation as resolved. Show resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
if !httpapi.Read(ctx, rw, r, ¶ms) { | ||
return | ||
} | ||
updateParams := database.UpdateTemplateVersionByIDParams{ | ||
ID: templateVersion.ID, | ||
TemplateID: templateVersion.TemplateID, | ||
UpdatedAt: database.Now(), | ||
Name: templateVersion.Name, | ||
} | ||
if params.Name != "" { | ||
updateParams.Name = params.Name | ||
} | ||
// It is not allowed to "patch" the template ID, and reassign it. | ||
updatedTemplateVersion, err := api.Database.UpdateTemplateVersionByID(ctx, updateParams) | ||
if err != nil { | ||
httpapi.Write(ctx, rw, http.StatusInternalServerError, codersdk.Response{ | ||
Message: "Error on patching template version.", | ||
Detail: err.Error(), | ||
}) | ||
return | ||
} | ||
job, err := api.Database.GetProvisionerJobByID(ctx, templateVersion.JobID) | ||
if err != nil { | ||
httpapi.Write(ctx, rw, http.StatusInternalServerError, codersdk.Response{ | ||
Message: "Internal error fetching provisioner job.", | ||
Detail: err.Error(), | ||
}) | ||
return | ||
} | ||
user, err := api.Database.GetUserByID(ctx, templateVersion.CreatedBy) | ||
if err != nil { | ||
httpapi.Write(ctx, rw, http.StatusInternalServerError, codersdk.Response{ | ||
Message: "Internal error on fetching user.", | ||
Detail: err.Error(), | ||
}) | ||
return | ||
} | ||
httpapi.Write(ctx, rw, http.StatusOK, convertTemplateVersion(updatedTemplateVersion, convertProvisionerJob(job), user)) | ||
} | ||
// @Summary Cancel template version by ID | ||
// @ID cancel-template-version-by-id | ||
// @Security CoderSessionToken | ||
Uh oh!
There was an error while loading.Please reload this page.