link domain

neo4j-4
Josha von Gizycki 5 years ago
parent bd1fa8a7d7
commit 00ef765485

@ -4,7 +4,8 @@
[wanijo.framework.neo4j :as neo4j]
[wanijo.schema.domain :as domain-schema]
[wanijo.attribute.domain :as domain-attr]
[wanijo.tag.domain :as domain-tag]))
[wanijo.tag.domain :as domain-tag]
[wanijo.link.domain :as domain-link]))
(spec/def ::instance
(spec/keys :req-un [::neo4j/uuid
@ -17,10 +18,6 @@
::specs/created_at
::specs/updated_at
::domain-attr/attribute])))
(spec/def ::link
(spec/keys :req-un [::neo4j/uuid
::specs/created_at
::name]))
(spec/def ::target ::instance)
(spec/def ::source ::instance)
(spec/def ::tags
@ -182,26 +179,6 @@
(defn delete! [uuid]
(neo4j/exec-query! delete {:uuid uuid}))
(neo4j/defquery create-link
"MATCH (i:instance {uuid:{from}}),
(u:user {uuid:{by}}),
(t:instance {uuid:{target}})
CREATE (l:link {uuid:{uuid}})-[:created_by]->(u)
SET l.created_at = {created_at},
l.name = {name}
CREATE (i)<-[:link_from]-(l)-[:link_to]->(t)")
(defn create-link! [link]
(let [tuples (map (fn [target-uuid]
[create-link
{:from (:from link)
:by (:by link)
:target target-uuid
:uuid (neo4j/uuid)
:created_at (neo4j/now-str)
:name (:name link)}])
(:to link))]
(apply neo4j/exec-queries! tuples)))
(defn group-by-link-and-assoc-tags [uuid query direction]
(->> (neo4j/exec-query! query
{:uuid uuid})
@ -221,7 +198,7 @@
(spec/def ::links-out
(spec/coll-of
(spec/keys :req-un [::link
(spec/keys :req-un [::domain-link/link
::target
::domain-schema/schema
::tags])))
@ -239,7 +216,7 @@
(spec/def ::links-in
(spec/coll-of
(spec/keys :req-un [::link
(spec/keys :req-un [::domain-link/link
::source
::domain-schema/schema
::tags])))
@ -256,14 +233,6 @@
{:post [(spec/assert ::links-in %)]}
(group-by-link-and-assoc-tags uuid incoming-links :source))
(neo4j/defquery delete-link
"MATCH (l:link {uuid:{uuid}}),
(l)-[r]-()
DELETE r, l")
(defn delete-link! [uuid]
(neo4j/exec-query! delete-link
{:uuid uuid}))
(spec/def ::contains-full-information
(spec/keys :req-un [::properties
::links-out

@ -10,6 +10,7 @@
[wanijo.schema
[domain :as domain-schema]
[middleware :as middleware-schema]]
[wanijo.link.domain :as domain-link]
[wanijo.framework.routing :refer [register! path]]
[wanijo.attribute.domain :as domain-attr]))
@ -49,7 +50,7 @@
(domain-schema/accessible-schemas! user-uuid)
req)))
(defn form! [uuid attrs]
(defn form! [attrs]
(forms-inst/with-attributes attrs))
(defn edit-form! [uuid req]
@ -57,15 +58,14 @@
attrs (domain-attr/find-by-instance! uuid)
user-uuid (get-in req [:session :uuid])]
(view/edit! instance
(form! uuid attrs)
(form! attrs)
(forms-inst/instance->form-data instance)
(domain-schema/accessible-schemas! user-uuid)
req)))
(defn edit! [uuid req]
(let [attrs (domain-attr/find-by-instance! uuid)
form-def (form! uuid attrs)
instance (instance! uuid)]
form-def (form! attrs)]
(if (form/valid? form-def req)
(let [form-data (form/form-data form-def req)
form-instance (forms-inst/form-data->instance form-data attrs)
@ -94,7 +94,7 @@
(let [form (link-form! schema-uuid)]
(if (form/valid? form req)
(let [form-data (form/form-data form req)]
(domain/create-link! {:from uuid
(domain-link/create! {:from uuid
:name (:name form-data)
:to (:instances form-data)
:by (get-in req [:session :uuid])})
@ -102,7 +102,7 @@
(link-selection! uuid schema-uuid req))))
(defn delete-link! [uuid link-uuid req]
(domain/delete-link! link-uuid)
(domain-link/delete! link-uuid)
(resp/redirect (path :instance-edit-form {:uuid uuid})))
(defn mark-starred! [uuid req]

@ -0,0 +1,39 @@
(ns wanijo.link.domain
(:require [clojure.spec.alpha :as spec]
[wanijo.specs :as specs]
[wanijo.framework.neo4j :as neo4j]))
(spec/def ::link
(spec/keys :req-un [::neo4j/uuid
::specs/created_at
::name]))
(neo4j/defquery create
"MATCH (i:instance {uuid:{from}}),
(u:user {uuid:{by}}),
(t:instance {uuid:{target}})
CREATE
(l:link {uuid:{uuid}})-[:created_by]->(u)
SET l.created_at = {created_at},
l.name = {name}
CREATE
(i)<-[:link_from]-(l)-[:link_to]->(t)")
(defn create! [link]
(let [tuples (map (fn [target-uuid]
[create
{:from (:from link)
:by (:by link)
:target target-uuid
:uuid (neo4j/uuid)
:created_at (neo4j/now-str)
:name (:name link)}])
(:to link))]
(apply neo4j/exec-queries! tuples)))
(neo4j/defquery delete
"MATCH (l:link {uuid:{uuid}}),
(l)-[r]-()
DELETE r, l")
(defn delete! [uuid]
(neo4j/exec-query! delete
{:uuid uuid}))
Loading…
Cancel
Save