@Summary Get template examples @ID get-template-examples @Security CoderSessionToken @Produce json @Tags Templates @Success 200 {array} codersdk.TemplateExample @Router /api/v2/templates/examples [get]
(rw http.ResponseWriter, r *http.Request)
| 947 | // @Success 200 {array} codersdk.TemplateExample |
| 948 | // @Router /api/v2/templates/examples [get] |
| 949 | func (api *API) templateExamples(rw http.ResponseWriter, r *http.Request) { |
| 950 | ctx := r.Context() |
| 951 | |
| 952 | if !api.Authorize(r, policy.ActionRead, rbac.ResourceTemplate.AnyOrganization()) { |
| 953 | httpapi.ResourceNotFound(rw) |
| 954 | return |
| 955 | } |
| 956 | |
| 957 | ex, err := examples.List() |
| 958 | if err != nil { |
| 959 | httpapi.Write(ctx, rw, http.StatusInternalServerError, codersdk.Response{ |
| 960 | Message: "Internal error fetching examples.", |
| 961 | Detail: err.Error(), |
| 962 | }) |
| 963 | return |
| 964 | } |
| 965 | |
| 966 | httpapi.Write(ctx, rw, http.StatusOK, ex) |
| 967 | } |
| 968 | |
| 969 | func (api *API) convertTemplates(templates []database.Template) []codersdk.Template { |
| 970 | apiTemplates := make([]codersdk.Template, 0, len(templates)) |
nothing calls this directly
no test coverage detected