Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
internal functions
  • Loading branch information
mtojek committed Oct 3, 2023
commit 11bfb1110ca7ec526d07ea1c5a9bf06abc7f7941
20 changes: 18 additions & 2 deletions coderd/insights.go
Original file line number Diff line number Diff line change
Expand Up @@ -257,9 +257,9 @@ func (api *API) insightsTemplates(rw http.ResponseWriter, r *http.Request) {
endTimeString = p.String(vals, "", "end_time")
intervalString = p.String(vals, "", "interval")
templateIDs = p.UUIDs(vals, []uuid.UUID{}, "template_ids")
sections = codersdk.StringsAsTemplateInsightsSections(
sections = stringsAsTemplateInsightsSections(
p.Strings(vals,
codersdk.TemplateInsightsSectionAsStrings(codersdk.TemplateInsightsSectionIntervalReports, codersdk.TemplateInsightsSectionReport),
templateInsightsSectionAsStrings(codersdk.TemplateInsightsSectionIntervalReports, codersdk.TemplateInsightsSectionReport),
"sections")...)
)
p.ErrorExcessParams(vals)
Expand Down Expand Up @@ -674,3 +674,19 @@ func lastReportIntervalHasAtLeastSixDays(startTime, endTime time.Time) bool {
// when the duration can be shorter than 6 days: 5 days 23 hours.
return lastReportIntervalDays >= 6*24*time.Hour || startTime.AddDate(0, 0, 6).Equal(endTime)
}

func templateInsightsSectionAsStrings(sections ...codersdk.TemplateInsightsSection) []string {
t := make([]string, len(sections))
for i, s := range sections {
t[i] = string(s)
}
return t
}

func stringsAsTemplateInsightsSections(sections ...string) []codersdk.TemplateInsightsSection {
t := make([]codersdk.TemplateInsightsSection, len(sections))
for i, s := range sections {
t[i] = codersdk.TemplateInsightsSection(s)
}
return t
}
18 changes: 0 additions & 18 deletions codersdk/insights.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,24 +47,6 @@ const (
TemplateInsightsSectionReport TemplateInsightsSection = "report"
)

// TemplateInsightsSectionAsStrings converts section enums into a slice of strings.
func TemplateInsightsSectionAsStrings(sections ...TemplateInsightsSection) []string {
t := make([]string, len(sections))
for i, s := range sections {
t[i] = string(s)
}
return t
}

// StringsAsTemplateInsightsSections converts a slice of strings into section enums.
func StringsAsTemplateInsightsSections(sections ...string) []TemplateInsightsSection {
t := make([]TemplateInsightsSection, len(sections))
for i, s := range sections {
t[i] = TemplateInsightsSection(s)
}
return t
}

// UserLatencyInsightsResponse is the response from the user latency insights
// endpoint.
type UserLatencyInsightsResponse struct {
Expand Down