Skip to content

Commit ba9ee36

Browse files
committed
add search to /templates
1 parent cdeb293 commit ba9ee36

File tree

1 file changed

+7
-16
lines changed

1 file changed

+7
-16
lines changed

coderd/templates.go

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import (
2121
"github.com/coder/coder/v2/coderd/rbac"
2222
"github.com/coder/coder/v2/coderd/rbac/policy"
2323
"github.com/coder/coder/v2/coderd/schedule"
24+
"github.com/coder/coder/v2/coderd/searchquery"
2425
"github.com/coder/coder/v2/coderd/telemetry"
2526
"github.com/coder/coder/v2/coderd/util/ptr"
2627
"github.com/coder/coder/v2/coderd/workspacestats"
@@ -457,20 +458,12 @@ func (api *API) fetchTemplates(mutate func(r *http.Request, arg *database.GetTem
457458
return func(rw http.ResponseWriter, r *http.Request) {
458459
ctx := r.Context()
459460

460-
p := httpapi.NewQueryParamParser()
461-
values := r.URL.Query()
462-
463-
deprecated := sql.NullBool{}
464-
if values.Has("deprecated") {
465-
deprecated = sql.NullBool{
466-
Bool: p.Boolean(values, false, "deprecated"),
467-
Valid: true,
468-
}
469-
}
470-
if len(p.Errors) > 0 {
461+
queryStr := r.URL.Query().Get("q")
462+
filter, errs := searchquery.Templates(ctx, api.Database, queryStr)
463+
if len(errs) > 0 {
471464
httpapi.Write(ctx, rw, http.StatusBadRequest, codersdk.Response{
472-
Message: "Invalid query params.",
473-
Validations: p.Errors,
465+
Message: "Invalid template search query.",
466+
Validations: errs,
474467
})
475468
return
476469
}
@@ -484,9 +477,7 @@ func (api *API) fetchTemplates(mutate func(r *http.Request, arg *database.GetTem
484477
return
485478
}
486479

487-
args := database.GetTemplatesWithFilterParams{
488-
Deprecated: deprecated,
489-
}
480+
args := filter
490481
if mutate != nil {
491482
mutate(r, &args)
492483
}

0 commit comments

Comments
 (0)