diff --git a/src/wanijo/attribute/db.clj b/src/wanijo/attribute/db.clj index 23b6fe7..5009ff5 100644 --- a/src/wanijo/attribute/db.clj +++ b/src/wanijo/attribute/db.clj @@ -1,20 +1,7 @@ (ns wanijo.attribute.db - (:require [clojure.spec.alpha :as spec] - [wanijo.specs :as specs] - [wanijo.infrastructure.neo4j :as neo4j])) + (:require [wanijo.infrastructure.neo4j :as neo4j])) -(def types - #{"string" "markdown"}) -(spec/def ::type types) -(spec/def ::name - (spec/and ::specs/name (complement empty?))) -(spec/def ::attribute - (spec/keys ::req-un [::name - ::type - ::specs/created-at])) - -(neo4j/defquery - findy-by-schema +(neo4j/defquery findy-by-schema "MATCH (a:attribute)-->(s:schema) WHERE s.uuid = {uuid} RETURN a @@ -22,8 +9,8 @@ (defn find-by-schema! [schema-uuid] (map :a (neo4j/exec-query! - findy-by-schema - {:uuid schema-uuid}))) + findy-by-schema + {:uuid schema-uuid}))) (neo4j/defquery create-new "MATCH (s:schema {uuid:{schema_uuid}}), @@ -38,12 +25,12 @@ SET a.created_at = {created_at}") (defn create-new! [attr schema-uuid user-uuid] (neo4j/exec-query! - create-new - (assoc attr - :user_uuid user-uuid - :schema_uuid schema-uuid - :attribute_uuid (neo4j/uuid) - :created_at (neo4j/now-str)))) + create-new + (assoc attr + :user_uuid user-uuid + :schema_uuid schema-uuid + :attribute_uuid (neo4j/uuid) + :created_at (neo4j/now-str)))) (neo4j/defquery edit "MATCH (a:attribute) @@ -53,8 +40,8 @@ SET a.required = {required}") (defn edit! [attr] (neo4j/exec-query! - edit - attr)) + edit + attr)) (neo4j/defquery delete-by-uuid "MATCH (a:attribute)-[c]-() @@ -62,8 +49,8 @@ DELETE c, a") (defn delete-by-uuid! [uuid] (neo4j/exec-query! - delete-by-uuid - {:uuid uuid})) + delete-by-uuid + {:uuid uuid})) (neo4j/defquery required "MATCH (a:attribute)-[:of]->(s:schema {uuid:{schema_uuid}}) diff --git a/src/wanijo/attribute/domain.clj b/src/wanijo/attribute/domain.clj new file mode 100644 index 0000000..080b6e1 --- /dev/null +++ b/src/wanijo/attribute/domain.clj @@ -0,0 +1,13 @@ +(ns wanijo.attribute.domain + (:require [wanijo.specs :as specs] + [clojure.spec.alpha :as spec])) + +(def types + #{"string" "markdown"}) +(spec/def ::type types) +(spec/def ::name + (spec/and ::specs/name (complement empty?))) +(spec/def ::attribute + (spec/keys ::req-un [::name + ::type + ::specs/created-at])) diff --git a/src/wanijo/attribute/routes.clj b/src/wanijo/attribute/routes.clj index 6823efc..5b7489c 100644 --- a/src/wanijo/attribute/routes.clj +++ b/src/wanijo/attribute/routes.clj @@ -6,8 +6,6 @@ [wanijo.infrastructure.routing :refer [register! path]] [wanijo.attribute.db :as domain] [wanijo.schema - [view :as schema-view] - [db :as schema-domain] [routes :as schema-routes] [forms :as schema-forms] [middleware :as schema-middleware]])) diff --git a/src/wanijo/instance/db.clj b/src/wanijo/instance/db.clj index 95f7ea3..2f73edc 100644 --- a/src/wanijo/instance/db.clj +++ b/src/wanijo/instance/db.clj @@ -3,9 +3,9 @@ [wanijo.specs :as specs] [wanijo.infrastructure.neo4j :as neo4j] [wanijo.schema.db :as domain-schema] - [wanijo.attribute.db :as domain-attr] - [wanijo.tag.db :as domain-tag] - [wanijo.link.db :as domain-link])) + [wanijo.attribute.domain :as domain-attr] + [wanijo.tag.db :as db-tag] + [wanijo.link.db :as db-link])) (spec/def ::instance (spec/keys :req-un [::neo4j/uuid @@ -21,7 +21,7 @@ (spec/def ::target ::instance) (spec/def ::source ::instance) (spec/def ::tags - (spec/coll-of ::domain-tag/tag)) + (spec/coll-of ::db-tag/tag)) (spec/def ::contains-schema (spec/keys :req-un [::domain-schema/schema])) @@ -194,7 +194,7 @@ (spec/def ::links-out (spec/coll-of - (spec/keys :req-un [::domain-link/link + (spec/keys :req-un [::db-link/link ::target ::domain-schema/schema ::tags]))) @@ -212,7 +212,7 @@ (spec/def ::links-in (spec/coll-of - (spec/keys :req-un [::domain-link/link + (spec/keys :req-un [::db-link/link ::source ::domain-schema/schema ::tags]))) @@ -247,7 +247,7 @@ :links-in (incoming-links! uuid) :tags - (domain-tag/tags-by-instance! uuid))) + (db-tag/tags-by-instance! uuid))) (neo4j/defquery is-starred "MATCH (u:user {uuid:{user_uuid}}), diff --git a/src/wanijo/instance/routes.clj b/src/wanijo/instance/routes.clj index 6d0a1d1..feabe2b 100644 --- a/src/wanijo/instance/routes.clj +++ b/src/wanijo/instance/routes.clj @@ -12,22 +12,22 @@ [middleware :as middleware-schema]] [wanijo.link.db :as domain-link] [wanijo.infrastructure.routing :refer [register! path]] - [wanijo.attribute.db :as domain-attr])) + [wanijo.attribute.db :as db-attr])) (defn list! [schema-uuid req] (view/list! (domain-schema/find-by-uuid! schema-uuid) (domain/find-by-schema! schema-uuid) - (forms-inst/with-attributes (domain-attr/required! schema-uuid)) + (forms-inst/with-attributes (db-attr/required! schema-uuid)) req)) (defn new! [req] (let [schema-uuid (get-in req [:params :schema-uuid]) user-uuid (get-in req [:session :uuid]) - req-attrs (domain-attr/required! schema-uuid) + req-attrs (db-attr/required! schema-uuid) form-def (forms-inst/with-attributes req-attrs)] (if (form/valid? form-def req) (let [form-data (form/form-data form-def req) - req-attrs (domain-attr/required! schema-uuid) + req-attrs (db-attr/required! schema-uuid) instance (forms-inst/form-data->instance form-data req-attrs)] (domain/create! user-uuid @@ -55,7 +55,7 @@ (defn edit-form! [uuid req] (let [instance (instance! uuid) - attrs (domain-attr/find-by-instance! uuid) + attrs (db-attr/find-by-instance! uuid) user-uuid (get-in req [:session :uuid])] (view/edit! instance (form! attrs) @@ -64,7 +64,7 @@ req))) (defn edit! [uuid req] - (let [attrs (domain-attr/find-by-instance! uuid) + (let [attrs (db-attr/find-by-instance! uuid) form-def (form! attrs)] (if (form/valid? form-def req) (let [form-data (form/form-data form-def req) diff --git a/src/wanijo/schema/forms.clj b/src/wanijo/schema/forms.clj index 8d4d312..1933c06 100644 --- a/src/wanijo/schema/forms.clj +++ b/src/wanijo/schema/forms.clj @@ -1,5 +1,6 @@ (ns wanijo.schema.forms - (:require [wanijo.attribute.db :as attr-domain] + (:require [wanijo.attribute.db :as db-attr] + [wanijo.attribute.domain :as domain-attr] [clojure.string :refer [capitalize]] [clojure.spec.alpha :as spec])) @@ -7,7 +8,7 @@ (let [schema-uuid (get-in req [:params :schema]) attr-uuid (get-in req [:params :uuid]) name (get-in req [:params :name]) - duplicates (->> (attr-domain/find-by-schema! schema-uuid) + duplicates (->> (db-attr/find-by-schema! schema-uuid) (map #(if (or (and (empty? attr-uuid) (= name (:name %))) (and (seq attr-uuid) @@ -29,13 +30,13 @@ (def attr-form {:fields {:name {:label "Name" :required true - :spec ::attr-domain/name} + :spec ::domain-attr/name} :type {:label "Type" :required true - :spec ::attr-domain/type + :spec ::domain-attr/type :widget :select :options (map #(vector (capitalize %) %) - attr-domain/types)} + domain-attr/types)} :required {:label "Required" :required false :widget :checkbox diff --git a/src/wanijo/schema/routes.clj b/src/wanijo/schema/routes.clj index 58980f5..99480f2 100644 --- a/src/wanijo/schema/routes.clj +++ b/src/wanijo/schema/routes.clj @@ -10,7 +10,7 @@ [forms :as schema-forms] [db :as domain] [middleware :as middleware]] - [wanijo.attribute.db :as domain-attr])) + [wanijo.attribute.db :as db-attr])) (defn new! [req] (if (form/valid? schema-forms/schema req) @@ -28,7 +28,7 @@ (defn view! [uuid req] (schema-view/show-schema! (domain/find-with-assigned-entities! uuid) - (domain-attr/find-by-schema! uuid) + (db-attr/find-by-schema! uuid) (assoc-in schema-forms/assign-form [:fields :assigned :options] (map #(vector (:ident %) (:uuid %))