Skip to content
Snippets Groups Projects
Commit 4657a4a4 authored by Simon Belak's avatar Simon Belak
Browse files

Add schemas to api endpoints

parent 5abc1bce
Branches
Tags
No related merge requests found
......@@ -16,14 +16,35 @@
[query :refer [Query] :as query]
[segment :refer [Segment]]
[table :refer [Table]]]
[metabase.util.schema :as su]
[ring.util.codec :as codec]
[schema.core :as s]
[toucan
[db :as db]
[hydrate :refer [hydrate]]]))
(def ^:private Show (s/maybe (s/enum "all")))
(def ^:private Rule s/Str)
(def ^:private Prefix (->> ["table" "metric" "field"]
(mapcat rules/load-rules)
(filter :indepth)
(map :rule)
(apply s/enum)))
(def ^:private Rule (->> ["table" "metric" "field"]
(mapcat rules/load-rules)
(mapcat :indepth)
(map :rule)
(apply s/enum)))
(def ^:private ^{:arglists '([s])} decode-base64-json
(comp json/decode codecs/bytes->str codec/base64-decode))
(def ^:private Base64EncodedJSON (s/pred decode-base64-json))
(defn- load-rule
[entity prefix rule]
(rules/load-rule (format "%s/%s/%s.yaml" entity prefix rule)))
......@@ -35,16 +56,21 @@
api/check-404
magic/candidate-tables))
;; ----------------------------------------- API Endpoints for viewing a transient dashboard ----------------
(api/defendpoint GET "/table/:id"
"Return an automagic dashboard for table with id `ìd`."
[id show]
{show Show}
(-> id Table api/check-404 (magic/automagic-analysis {:show (keyword show)})))
(api/defendpoint GET "/table/:id/:prefix/:rule"
"Return an automagic dashboard for table with id `ìd` using rule `rule`."
[id prefix rule show]
{show Show
prefix Prefix
rule Rule}
(-> id
Table
api/check-404
......@@ -55,11 +81,15 @@
(api/defendpoint GET "/segment/:id"
"Return an automagic dashboard analyzing segment with id `id`."
[id show]
{show Show}
(-> id Segment api/check-404 (magic/automagic-analysis {:show (keyword show)})))
(api/defendpoint GET "/segment/:id/:prefix/:rule"
"Return an automagic dashboard analyzing segment with id `id`. using rule `rule`."
[id prefix rule show]
{show Show
prefix Prefix
rule Rule}
(-> id
Segment
api/check-404
......@@ -71,6 +101,8 @@
"Return an automagic dashboard analyzing cell in question with id `id` defined by
query `cell-querry`."
[id cell-query show]
{show Show
cell-query Base64EncodedJSON}
(-> id
Card
api/check-404
......@@ -81,6 +113,10 @@
"Return an automagic dashboard analyzing cell in question with id `id` defined by
query `cell-querry` using rule `rule`."
[id cell-query prefix rule show]
{show Show
prefix Prefix
rule Rule
cell-query Base64EncodedJSON}
(-> id
Card
api/check-404
......@@ -91,21 +127,26 @@
(api/defendpoint GET "/metric/:id"
"Return an automagic dashboard analyzing metric with id `id`."
[id show]
{show Show}
(-> id Metric api/check-404 (magic/automagic-analysis {:show (keyword show)})))
(api/defendpoint GET "/field/:id"
"Return an automagic dashboard analyzing field with id `id`."
[id show]
{show Show}
(-> id Field api/check-404 (magic/automagic-analysis {:show (keyword show)})))
(api/defendpoint GET "/question/:id"
"Return an automagic dashboard analyzing question with id `id`."
[id show]
{show Show}
(-> id Card api/check-404 (magic/automagic-analysis {:show (keyword show)})))
(api/defendpoint GET "/adhoc/:query"
"Return an automagic dashboard analyzing ad hoc query."
[query show]
{show Show
query Base64EncodedJSON}
(-> query
decode-base64-json
query/adhoc-query
......@@ -114,6 +155,9 @@
(api/defendpoint GET "/adhoc/:query/cell/:cell-query"
"Return an automagic dashboard analyzing ad hoc query."
[query cell-query show]
{show Show
query Base64EncodedJSON
cell-query Base64EncodedJSON}
(let [query (decode-base64-json query)
cell-query (decode-base64-json cell-query)]
(-> query
......
......@@ -145,7 +145,7 @@
[(-> field :table_id Table :display_name)
(:display_name field)]
[(:display_name field)])
:field-id (:id field)
:field_id (:id field)
:type (filter-type field)
:value rhs
:op op}))))))
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment