(ctx context.Context, rw http.ResponseWriter, sections []string)
| 802 | } |
| 803 | |
| 804 | func parseTemplateInsightsSections(ctx context.Context, rw http.ResponseWriter, sections []string) ([]codersdk.TemplateInsightsSection, bool) { |
| 805 | t := make([]codersdk.TemplateInsightsSection, len(sections)) |
| 806 | for i, s := range sections { |
| 807 | switch v := codersdk.TemplateInsightsSection(s); v { |
| 808 | case codersdk.TemplateInsightsSectionIntervalReports, codersdk.TemplateInsightsSectionReport: |
| 809 | t[i] = v |
| 810 | default: |
| 811 | httpapi.Write(ctx, rw, http.StatusBadRequest, codersdk.Response{ |
| 812 | Message: "Query parameter has invalid value.", |
| 813 | Validations: []codersdk.ValidationError{ |
| 814 | { |
| 815 | Field: "sections", |
| 816 | Detail: fmt.Sprintf("must be one of %v", []codersdk.TemplateInsightsSection{codersdk.TemplateInsightsSectionIntervalReports, codersdk.TemplateInsightsSectionReport}), |
| 817 | }, |
| 818 | }, |
| 819 | }) |
| 820 | return nil, false |
| 821 | } |
| 822 | } |
| 823 | return t, true |
| 824 | } |
no test coverage detected