-
Notifications
You must be signed in to change notification settings - Fork 5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
844 changed files
with
20,971 additions
and
15,126 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,7 @@ | ||
(ns macros.metabase.api.common | ||
(:require | ||
[clojure.string :as str])) | ||
(ns macros.metabase.api.common) | ||
|
||
(defmacro define-routes | ||
"Macro for api.common/define-routes" | ||
[& args] | ||
`(do (def ~'routes "docstring" nil) | ||
~@args)) | ||
|
||
(defn route-fn-name | ||
"route fn hook" | ||
[method route] | ||
(let [route (if (vector? route) (first route) route)] | ||
(-> (str (name method) route) | ||
(str/replace #"/" "_") | ||
symbol))) | ||
|
||
(defmacro defendpoint | ||
"Macro for api.common/defendpoint*" | ||
[method route & body] | ||
(let [method-fn (symbol "compojure.core" (str method)) | ||
route-name (route-fn-name method route)] | ||
`(do | ||
~method-fn | ||
(defn ~route-name ~@body)))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
(ns hooks.metabase.api.common | ||
(:require | ||
[clj-kondo.hooks-api :as api] | ||
[clojure.string :as str])) | ||
|
||
(defn route-fn-name | ||
"route fn hook" | ||
[method route] | ||
(let [route (if (vector? route) (first route) route)] | ||
(-> (str (name method) route) | ||
(str/replace #"/" "_") | ||
symbol))) | ||
|
||
(defn defendpoint | ||
[arg] | ||
(letfn [(update-defendpoint [node] | ||
(let [[_defendpoint method route & body] (:children node)] | ||
(api/list-node | ||
(list | ||
(api/token-node 'do) | ||
(api/token-node (symbol "compojure.core" (str (api/sexpr method)))) | ||
(-> (api/list-node | ||
(list* | ||
(api/token-node 'clojure.core/defn) | ||
(api/token-node (route-fn-name (api/sexpr method) (api/sexpr route))) | ||
body)) | ||
(with-meta (meta node)))))))] | ||
(update arg :node update-defendpoint))) | ||
|
||
(comment | ||
(-> {:node (-> '(api/defendpoint POST "/:id/copy" | ||
"Copy a `Card`, with the new name 'Copy of _name_'" | ||
[id] | ||
{id [:maybe ms/PositiveInt]} | ||
(let [orig-card (api/read-check Card id) | ||
new-name (str (trs "Copy of ") (:name orig-card)) | ||
new-card (assoc orig-card :name new-name)] | ||
(-> (card/create-card! new-card @api/*current-user*) | ||
hydrate-card-details | ||
(assoc :last-edit-info (last-edit/edit-information-for-user @api/*current-user*))))) | ||
pr-str | ||
api/parse-string)} | ||
defendpoint | ||
:node | ||
api/sexpr)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.