Skip to content
Snippets Groups Projects
Commit ae600ada authored by Cam Saül's avatar Cam Saül
Browse files

GET /api/card/:id/json endpoint :100:

parent bc42c632
No related branches found
No related tags found
No related merge requests found
......@@ -258,6 +258,7 @@
;;; ------------------------------------------------------------ Running a Query ------------------------------------------------------------
(defn- run-query-for-card [card-id parameters]
{:pre [(u/maybe? sequential? parameters)]}
(let [card (read-check Card card-id)
query (assoc (:dataset_query card)
:parameters parameters
......@@ -276,5 +277,12 @@
[card-id :as {{:keys [parameters]} :body}]
(dataset-api/as-csv (run-query-for-card card-id parameters)))
(defendpoint GET "/:card-id/json"
"Fetch the results of a Card as JSON."
[card-id]
(let [{{:keys [columns rows]} :data} (run-query-for-card card-id nil)]
(for [row rows]
(zipmap columns row))))
(define-routes)
......@@ -340,3 +340,13 @@
(do-with-temp-native-card
(fn [database-id card]
((user->client :rasta) :post 403 (format "card/%d/query/csv" (u/get-id card))))))
;;; Tests for GET /api/card/:id/json
;; endpoint should return an array of maps, one for each row
(expect
[{(keyword "COUNT(*)") 75}]
(do-with-temp-native-card
(fn [database-id card]
(perms/grant-native-read-permissions! (perms-group/all-users) database-id)
((user->client :rasta) :get 200 (format "card/%d/json" (u/get-id card))))))
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