Skip to content
Snippets Groups Projects
Commit 7260ab15 authored by Tom Robinson's avatar Tom Robinson
Browse files

Refactor column selection for search endpoint, add archived etc

parent 20742fd7
No related branches found
No related tags found
No related merge requests found
......@@ -16,9 +16,32 @@
[schema.core :as s]
[toucan.db :as db]))
(def ^:priviate card-columns-without-type
[:id :name :description :archived :collection_id :collection_position])
(def ^:priviate dashboard-columns-without-type
[:id :name :description :archived :collection_id :collection_position])
(def ^:priviate pulse-columns-without-type
[:id :name :collection_id])
(def ^:priviate collection-columns-without-type
[:id :name :description :archived])
(def ^:priviate segment-columns-without-type
[:id :name :description :archived])
(def ^:priviate metric-columns-without-type
[:id :name :description :archived])
(def ^:private search-columns-without-type
"The columns found in search query clauses except type. Type is added automatically"
[:name :description :id])
(vec (set (concat card-columns-without-type
dashboard-columns-without-type
pulse-columns-without-type
collection-columns-without-type
segment-columns-without-type
metric-columns-without-type))))
(def ^:private SearchContext
"Map with the various allowed search parameters, used to construct the SQL query"
......@@ -78,7 +101,7 @@
(s/defmethod ^:private create-search-query :card
[_ search-ctx :- SearchContext]
(-> (make-honeysql-search-query Card "card" search-columns-without-type)
(-> (make-honeysql-search-query Card "card" card-columns-without-type)
(merge-name-and-archived-search search-ctx)
(add-collection-criteria :collection_id search-ctx)))
......@@ -86,13 +109,13 @@
[_ {:keys [collection] :as search-ctx} :- SearchContext]
;; If we have a collection, no need to search collections
(when-not collection
(-> (make-honeysql-search-query Collection "collection" search-columns-without-type)
(-> (make-honeysql-search-query Collection "collection" collection-columns-without-type)
(merge-name-and-archived-search search-ctx)
(add-collection-criteria :id search-ctx))))
(s/defmethod ^:private create-search-query :dashboard
[_ search-ctx :- SearchContext]
(-> (make-honeysql-search-query Dashboard "dashboard" search-columns-without-type)
(-> (make-honeysql-search-query Dashboard "dashboard" dashboard-columns-without-type)
(merge-name-and-archived-search search-ctx)
(add-collection-criteria :collection_id search-ctx)))
......@@ -100,20 +123,20 @@
[_ {:keys [archived?] :as search-ctx} :- SearchContext]
;; Pulses don't currently support being archived, omit if archived is true
(when-not archived?
(-> (make-honeysql-search-query Pulse "pulse" [:name :id])
(-> (make-honeysql-search-query Pulse "pulse" pulse-columns-without-type)
(merge-name-search search-ctx)
(add-collection-criteria :collection_id search-ctx))))
(s/defmethod ^:private create-search-query :metric
[_ {:keys [collection] :as search-ctx} :- SearchContext]
(when-not collection
(-> (make-honeysql-search-query Metric "metric" search-columns-without-type)
(-> (make-honeysql-search-query Metric "metric" metric-columns-without-type)
(merge-name-and-archived-search search-ctx))))
(s/defmethod ^:private create-search-query :segment
[_ {:keys [collection] :as search-ctx} :- SearchContext]
(when-not collection
(-> (make-honeysql-search-query Segment "segment" search-columns-without-type)
(-> (make-honeysql-search-query Segment "segment" segment-columns-without-type)
(merge-name-and-archived-search search-ctx))))
(s/defn ^:private search
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment