move specs to domain namespace

integration-tests
Josha von Gizycki 7 years ago
parent 2fdce3b2e7
commit 4ba0d397e9

@ -1,7 +1,17 @@
(ns wanijo.domain.schema (ns wanijo.domain.schema
(:require [clojurewerkz.neocons.rest.cypher :as cypher] (:require [clojurewerkz.neocons.rest.cypher :as cypher]
[clojure.spec.alpha :as spec]
[wanijo.neo4j :as neo4j])) [wanijo.neo4j :as neo4j]))
(spec/def ::name
(spec/and string? not-empty))
(spec/def ::created-at
(spec/or :int (spec/and int?
#(> % 20000101000000))
:str (spec/and string?
#(re-matches #"\d{4}\d{2}\d{2}\d{2}\d{2}\d{2}" %))))
(defn all-created-by! [ident] (defn all-created-by! [ident]
(->> (->>
(cypher/tquery (cypher/tquery
@ -9,6 +19,6 @@
"MATCH (s:schema)-[created_by]->(u:user) "MATCH (s:schema)-[created_by]->(u:user)
WHERE u.ident = {ident} WHERE u.ident = {ident}
RETURN s RETURN s
ORDER BY s.created_at" ORDER BY s.name"
{:ident ident}) {:ident ident})
(map #(:data (get % "s"))))) (map #(:data (get % "s")))))

@ -28,3 +28,14 @@
(hform/text-field {:required (when required "required")} (hform/text-field {:required (when required "required")}
field field
(get-in req [:params field]))))) (get-in req [:params field])))))
(defn valid? [req form-def]
(reduce-kv
(fn [result field value]
(if (spec/valid?
(get-in form-def [:fields field :spec])
value)
true
(reduced false)))
true
(:params req)))

@ -3,18 +3,14 @@
[ring.util.anti-forgery :refer [anti-forgery-field]] [ring.util.anti-forgery :refer [anti-forgery-field]]
[ring.util.response :as resp] [ring.util.response :as resp]
[hiccup.form :as hform] [hiccup.form :as hform]
[clojure.spec.alpha :as spec]
[wanijo.domain.schema :as domain-schemas] [wanijo.domain.schema :as domain-schemas]
[wanijo.view :as view] [wanijo.view :as view]
[wanijo.forms :as forms])) [wanijo.forms :as forms]))
(spec/def ::schema-name
(spec/and some? string? not-empty))
(def new-schema-form (def new-schema-form
{:fields {:schema-name {:label "Nimi" {:fields {:schema-name {:label "Nimi"
:required true :required true
:spec ::schema-name}}}) :spec :wanijo.domain.schema/name}}})
(defn- overview! [req] (defn- overview! [req]
(let [session (:session req) (let [session (:session req)
@ -42,7 +38,7 @@
(anti-forgery-field))]))) (anti-forgery-field))])))
(defn- new! [req] (defn- new! [req]
(if (spec/valid? ::new-schema (:params req)) (if (forms/valid? req new-schema-form)
(resp/redirect "/schema") (resp/redirect "/schema")
(overview! req))) (overview! req)))

Loading…
Cancel
Save