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

Add transient endpoints

parent c52d1740
No related branches found
No related tags found
No related merge requests found
......@@ -13,31 +13,61 @@
[db :as db]
[hydrate :refer [hydrate]]]))
; Should be POST, GET for testing convinience
(api/defendpoint GET "/database/:id"
"Return automagic dashboards for all visible tables in database with id `ìd`."
[id]
(->> (db/select Table
:db_id id
:visibility_type nil)
(remove (some-fn magic/link-table? magic/list-like-table?))
(keep magic/automagic-dashboard)))
(api/defendpoint GET "/table/:id"
"Return an automagic dashboard for table with id `ìd`."
[id]
(magic/automagic-dashboard (Table id)))
(api/defendpoint GET "/analize/metric/:id"
"Return an automagic dashboard analyzing metric with id `id`."
[id]
(magic/automagic-analysis (Metric id)))
(api/defendpoint GET "/compare/dashboard/:dashboard-id/segments/:left-id/:right-id"
"Return an automagic comparison dashboard based on dashboard with ID
`dashboard-id`, comparing segments with IDs `left-id` and `right-id`."
[dashboard-id left-id right-id]
(-> (Dashboard dashboard-id)
api/check-404
(hydrate [:ordered_cards [:card :in_public_dashboard] :series])
(magic.comparison/comparison-dashboard (Segment left-id) (Segment right-id))))
;; ----------------------------------------- for testing convinience ----------------
(api/defendpoint GET "/database/:id/save"
"Create automagic dashboards for all visible tables in database with id `ìd`."
[id]
(->> (db/select Table
:db_id id
:visibility_type nil)
(remove (some-fn magic/link-table? magic/single-field-table?))
(keep magic/automagic-dashboard)
(remove (some-fn magic/link-table? magic/list-like-table?))
(mapcat magic/automagic-dashboard)
(map (comp :id dashboard/save-transient-dashboard!))))
(api/defendpoint GET "/table/:id"
(api/defendpoint GET "/table/:id/save"
"Create an automagic dashboard for table with id `ìd`."
[id]
(->> (magic/automagic-dashboard (Table id))
(map comp :id dashboard/save-transient-dashboard!)))
(map (comp :id dashboard/save-transient-dashboard!))))
(api/defendpoint GET "/analize/metric/:id"
(api/defendpoint GET "/analize/metric/:id/save"
"Create an automagic dashboard analyzing metric with id `id`."
[id]
[(-> (magic/automagic-analysis (Metric id))
dashboard/save-transient-dashboard!
:id)])
(api/defendpoint GET "/compare/dashboard/:dashboard-id/segments/:left-id/:right-id"
(api/defendpoint GET "/compare/dashboard/:dashboard-id/segments/:left-id/:right-id/save"
"Create an automagic comparison dashboard based on dashboard with ID
`dashboard-id`, comparing segments with IDs `left-id` and `right-id`."
[dashboard-id left-id right-id]
......
......@@ -348,7 +348,7 @@
[:or [:not-in :special_type ["type/FK" "type/PK"]]
[:= :special_type nil]]]})))
(defn single-field-table?
(defn list-like-table?
"Is the table comprised of only primary key and single field?"
[table]
(= 1 (db/count Field
......
......@@ -251,7 +251,8 @@
(->> rules-dir
clojure.java.io/file
.listFiles
(map load-rule)))
(filter (memfn ^java.io.File isFile))
(keep load-rule)))
(defn -main
"Entry point for lein task `validate-automagic-dashboards`"
......
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