refactorings and corrections

integration-tests
Josha von Gizycki 6 years ago
parent 05384a9f2d
commit 3982f5728f

@ -22,10 +22,13 @@
:plugins [[joshavg/lein-neo4j "0.3.0"] :plugins [[joshavg/lein-neo4j "0.3.0"]
[lein-less "1.7.5"] [lein-less "1.7.5"]
[lein-ring "0.9.7"] [lein-ring "0.9.7"]
[lein-ancient "0.6.15"]]} [lein-ancient "0.6.15"]
[jonase/eastwood "0.2.9"]
[lein-bikeshed "0.5.0"]]}
:uberjar {:aot :all}} :uberjar {:aot :all}}
:ring {:handler wanijo.handler/app} :ring {:handler wanijo.handler/app}
:less {:source-paths ["resources/app/stylesheets"] :less {:source-paths ["resources/app/stylesheets"]
:target-path "resources/public/css"} :target-path "resources/public/css"}
:hiera {:cluster-depth 2}) :hiera {:cluster-depth 2}
:eastwood {:namespaces [:source-paths]})

@ -5,7 +5,8 @@
[wanijo.framework.routing :refer [register! path]] [wanijo.framework.routing :refer [register! path]]
[wanijo.attribute.domain :as domain] [wanijo.attribute.domain :as domain]
[wanijo.schema.view :as view-schema] [wanijo.schema.view :as view-schema]
[wanijo.schema.domain :as domain-schema])) [wanijo.schema.domain :as domain-schema]
[wanijo.schema.routes :as routes-schema]))
(defn new! [req] (defn new! [req]
(let [schema-uuid (get-in req [:params :schema])] (let [schema-uuid (get-in req [:params :schema])]
@ -16,20 +17,14 @@
schema-uuid schema-uuid
(get-in req [:session :uuid])) (get-in req [:session :uuid]))
(resp/redirect (path :schema-show {:uuid schema-uuid}))) (resp/redirect (path :schema-show {:uuid schema-uuid})))
(view-schema/show-schema! (routes-schema/view! schema-uuid req))))
(domain-schema/find-by-uuid! schema-uuid)
(domain/find-by-schema! schema-uuid)
req))))
(defn edit! [schema-uuid req] (defn edit! [schema-uuid req]
(if (form/valid? view-schema/attr-form req) (if (form/valid? view-schema/attr-form req)
(do (do
(domain/edit! (:params req)) (domain/edit! (:params req))
(resp/redirect (path :schema-show {:uuid schema-uuid}))) (resp/redirect (path :schema-show {:uuid schema-uuid})))
(view-schema/show-schema! (routes-schema/view! schema-uuid req)))
(domain-schema/find-by-uuid! schema-uuid)
(domain/find-by-schema! schema-uuid)
req)))
(defn delete! [uuid req] (defn delete! [uuid req]
(domain/delete-by-uuid! uuid) (domain/delete-by-uuid! uuid)

@ -110,7 +110,11 @@
options options
(if validate? req-value value)))) (if validate? req-value value))))
(defn render-multiselect [id {:keys [label spec options]} value req-value validate?] (defn render-multiselect [id
{:keys [label spec options]}
value
req-value
validate?]
(list (list
(when (and validate? (not (spec/valid? spec req-value))) (when (and validate? (not (spec/valid? spec req-value)))
(spec-to-errmsg label spec value)) (spec-to-errmsg label spec value))

@ -9,12 +9,12 @@
assoc id path) assoc id path)
path) path)
(defn check-params [id path params] (defn check-params [path params]
(when (nil? path) (when (nil? path)
(throw (throw
(ex-info (ex-info
(str "Path " id " is not registered") "Path is not registered"
{:id id {:path path
:params params}))) :params params})))
(let [matcher (re-matcher #":[^/]+" path) (let [matcher (re-matcher #":[^/]+" path)
matches (take-while some? (repeatedly #(re-find matcher)))] matches (take-while some? (repeatedly #(re-find matcher)))]
@ -28,10 +28,10 @@
"' does not exist in parameter map for path " "' does not exist in parameter map for path "
path) path)
{:path path {:path path
:params params :params params}))))))
:id id}))))))
(defn parse-path [path params] (defn parse-path [path params]
(check-params path params)
(reduce-kv (reduce-kv
(fn [new-path param-id param-value] (fn [new-path param-id param-value]
(string/replace (string/replace
@ -46,5 +46,4 @@
(path id {})) (path id {}))
([id params] ([id params]
(let [path (id @all-routes)] (let [path (id @all-routes)]
(check-params id path params)
(parse-path path params)))) (parse-path path params))))

@ -18,17 +18,6 @@
(resp/redirect (path :schema-overview))) (resp/redirect (path :schema-overview)))
(view-schema/overview! req))) (view-schema/overview! req)))
(defn edit! [req]
(let [uuid (get-in req [:params :uuid])]
(if (form/valid? view-schema/form req)
(do
(domain/edit! (:params req))
(resp/redirect (path :schema-show (:params req))))
(view-schema/show-schema!
(domain/find-by-uuid! uuid)
(domain-attr/find-by-schema! uuid)
req))))
(defn delete-schema! [uuid session] (defn delete-schema! [uuid session]
(if (domain/can-user-modify? uuid (:uuid session)) (if (domain/can-user-modify? uuid (:uuid session))
(do (do
@ -46,6 +35,14 @@
(domain-user/all!))) (domain-user/all!)))
req)) req))
(defn edit! [req]
(let [uuid (get-in req [:params :uuid])]
(if (form/valid? view-schema/form req)
(do
(domain/edit! (:params req))
(resp/redirect (path :schema-show (:params req))))
(view! uuid req))))
(defn assign! [req] (defn assign! [req]
(let [uuid (get-in req [:params :uuid]) (let [uuid (get-in req [:params :uuid])
users (get-in req [:params :assigned])] users (get-in req [:params :assigned])]
@ -59,8 +56,6 @@
(resp/redirect (path :schema-show (:params req)))) (resp/redirect (path :schema-show (:params req))))
(view! uuid req)))) (view! uuid req))))
;; random change
(defroutes routes (defroutes routes
(GET (register! :schema-overview "/schema") (GET (register! :schema-overview "/schema")
[] []

@ -89,7 +89,8 @@
(anti-forgery-field) (anti-forgery-field)
(hform/hidden-field "schema" (:uuid schema)) (hform/hidden-field "schema" (:uuid schema))
(hform/submit-button {:class "delete-btn"} "Delete!") (hform/submit-button {:class "delete-btn"} "Delete!")
[:label "Created at " [:em (prettify-dt (:created_at attr))]])])] [:label "Created at "
[:em (prettify-dt (:created_at attr))]])])]
[:h3 "New attribute"] [:h3 "New attribute"]
(hform/form-to [:post (path :attribute-new)] (hform/form-to [:post (path :attribute-new)]
(form/render-widgets attr-form {} req) (form/render-widgets attr-form {} req)

@ -14,4 +14,4 @@
(testing "additional params are ignored" (testing "additional params are ignored"
(is (= (parse-path ":a" {:a 1 :b 2}) "1"))) (is (= (parse-path ":a" {:a 1 :b 2}) "1")))
(testing "all params are required" (testing "all params are required"
(is (thrown? RuntimeException (parse-path ":a"))))) (is (thrown? RuntimeException (parse-path ":a" {})))))

Loading…
Cancel
Save