Store uncoerced query-params in frontend match

This matches path-params and fragment.
This commit is contained in:
Juho Teperi 2018-08-22 11:01:53 +03:00
parent c11d21d9ec
commit 0bd1b94274
2 changed files with 7 additions and 2 deletions

View file

@ -21,9 +21,10 @@
(let [uri (.parse Uri path)] (let [uri (.parse Uri path)]
(if-let [match (reitit/match-by-path router (.getPath uri))] (if-let [match (reitit/match-by-path router (.getPath uri))]
(let [q (query-params uri) (let [q (query-params uri)
match (assoc match :query-params q)
;; Return uncoerced values if coercion is not enabled - so ;; Return uncoerced values if coercion is not enabled - so
;; that tha parameters are always accessible from same property. ;; that tha parameters are always accessible from same property.
parameters (or (coercion/coerce! (assoc match :query-params q)) parameters (or (coercion/coerce! match)
{:path (:path-params match) {:path (:path-params match)
:query q})] :query q})]
(assoc match :parameters parameters))))) (assoc match :parameters parameters)))))

View file

@ -20,6 +20,7 @@
{:template "/" {:template "/"
:data {:name ::frontpage} :data {:name ::frontpage}
:path-params {} :path-params {}
:query-params {}
:path "/" :path "/"
:parameters {:query {} :parameters {:query {}
:path {}}}) :path {}}})
@ -32,6 +33,7 @@
{:template "/foo" {:template "/foo"
:data {:name ::foo} :data {:name ::foo}
:path-params {} :path-params {}
:query-params {}
:path "/foo" :path "/foo"
:parameters {:query {} :parameters {:query {}
:path {}}}) :path {}}})
@ -59,6 +61,7 @@
(is (= (r/map->Match (is (= (r/map->Match
{:template "/:id" {:template "/:id"
:path-params {:id "5"} :path-params {:id "5"}
:query-params {}
:path "/5" :path "/5"
:parameters {:query {} :parameters {:query {}
:path {:id 5}}}) :path {:id 5}}})
@ -71,7 +74,7 @@
(is (= (r/map->Match (is (= (r/map->Match
{:template "/:id" {:template "/:id"
:path-params {:id "5"} :path-params {:id "5"}
;; Note: query not included in path :query-params {:mode "foo"}
:path "/5" :path "/5"
:parameters {:path {:id 5} :parameters {:path {:id 5}
:query {:mode :foo}}}) :query {:mode :foo}}})
@ -84,6 +87,7 @@
(is (= (r/map->Match (is (= (r/map->Match
{:template "/:id" {:template "/:id"
:path-params {:id "5"} :path-params {:id "5"}
:query-params {:mode "foo"}
:path "/5" :path "/5"
:parameters {:path {:id 5} :parameters {:path {:id 5}
:query {:mode :foo}}}) :query {:mode :foo}}})