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
(:require [clojurewerkz.neocons.rest.cypher :as cypher]
[clojure.spec.alpha :as spec]
[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]
(->>
(cypher/tquery
@ -9,6 +19,6 @@
"MATCH (s:schema)-[created_by]->(u:user)
WHERE u.ident = {ident}
RETURN s
ORDER BY s.created_at"
ORDER BY s.name"
{:ident ident})
(map #(:data (get % "s")))))

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

Loading…
Cancel
Save