creation of revisions

master
Josha von Gizycki 3 years ago
parent 4e5c86b808
commit 21ef517cec

@ -2,7 +2,8 @@
(:require [clojure.spec.alpha :as spec] (:require [clojure.spec.alpha :as spec]
[wanijo.infra.neo4j :as neo4j] [wanijo.infra.neo4j :as neo4j]
[wanijo.instance.domain :as domain-instance] [wanijo.instance.domain :as domain-instance]
[wanijo.tag.db :as db-tag])) [wanijo.tag.db :as db-tag]
[wanijo.instance.revision.db :as db-rev]))
(neo4j/defquery findy-by-schema (neo4j/defquery findy-by-schema
"MATCH (i:instance)-[:of]->(s:schema) "MATCH (i:instance)-[:of]->(s:schema)
@ -125,14 +126,23 @@
:instance_uuid (:uuid instance) :instance_uuid (:uuid instance)
:attribute_uuid (-> prop :attribute :uuid)}])) :attribute_uuid (-> prop :attribute :uuid)}]))
(:properties instance))) (:properties instance)))
(defn edit! [instance] (defn edit! [instance revision]
(let [prop-tuples (instance->prop-tuples instance)] (let [prop-tuples (instance->prop-tuples instance)]
(apply neo4j/exec-queries! (apply neo4j/exec-queries!
(concat [[edit-instance (concat [[edit-instance
{:uuid (:uuid instance) {:uuid (:uuid instance)
:name (:name instance) :name (:name instance)
:updated_at (neo4j/now-str)}]] :updated_at (neo4j/now-str)}]]
prop-tuples)))) prop-tuples
(db-rev/revision-queries revision)))))
(comment
(db-rev/revision-queries
{:instance-name "dings"
:instance-uuid "4711"
:properties [{:type "string"
:value "dings-prop"}]})
)
(neo4j/defquery delete (neo4j/defquery delete
"MATCH (i:instance {uuid: $uuid}), "MATCH (i:instance {uuid: $uuid}),
@ -242,3 +252,4 @@
:starred_at (-> % :s :created_at)) :starred_at (-> % :s :created_at))
(neo4j/exec-query! starred-by-user (neo4j/exec-query! starred-by-user
{:user_uuid user-uuid}))) {:user_uuid user-uuid})))

@ -66,3 +66,12 @@
(spec/def ::full-instance (spec/def ::full-instance
(spec/merge ::instance-with-schema (spec/merge ::instance-with-schema
::contains-full-information)) ::contains-full-information))
(defn to-revision [instance]
{:instance-name (:name instance)
:instance-uuid (:uuid instance)
:properties
(map (fn [{:keys [attribute value]}]
{:value value
:type (:type attribute)})
(:properties instance))})

@ -0,0 +1,33 @@
(ns wanijo.instance.revision.db
(:require [wanijo.infra.neo4j :as neo4j]))
(neo4j/defquery save-revision
"MATCH (i:instance)
WHERE i.uuid = $uuid
CREATE (r:revision)-[:of]->(i)
SET r.uuid = $rev_uuid,
r.instance_name = $name,
r.created_at = $now")
(neo4j/defquery save-revision-property
"MATCH (r:revision)
WHERE r.uuid = $rev_uuid
CREATE (rp:rev_property)-[:of]->(r)
SET rp.uuid = $rp_uuid,
rp.value = $value,
rp.type = $type,
rp.created_at = $now")
(defn revision-queries [revision]
(let [rev-uuid (neo4j/uuid)]
(concat [[save-revision
{:uuid (:instance-uuid revision)
:rev_uuid rev-uuid
:name (:instance-name revision)
:now (neo4j/now-str)}]]
(map (fn [{:keys [value type]}]
[save-revision-property
{:rev_uuid rev-uuid
:rp_uuid (neo4j/uuid)
:value value
:type type
:now (neo4j/now-str)}])
(:properties revision)))))

@ -11,8 +11,10 @@
[link-selection :refer [link-selection]] [link-selection :refer [link-selection]]
[bulk-link-selection :refer [bulk-link-selection]] [bulk-link-selection :refer [bulk-link-selection]]
[starred :refer [starred]]] [starred :refer [starred]]]
[wanijo.instance.db :as domain] [wanijo.instance
[wanijo.instance.forms :as forms-inst] [db :as db]
[forms :as forms-inst]
[domain :as domain]]
[wanijo.schema.db :as domain-schema] [wanijo.schema.db :as domain-schema]
[wanijo.schema.middleware :as middleware-schema] [wanijo.schema.middleware :as middleware-schema]
[wanijo.link.db :as domain-link] [wanijo.link.db :as domain-link]
@ -21,7 +23,7 @@
(defn route-list! [schema-uuid req] (defn route-list! [schema-uuid req]
(instances (domain-schema/find-by-uuid! schema-uuid) (instances (domain-schema/find-by-uuid! schema-uuid)
(domain/find-by-schema! schema-uuid) (db/find-by-schema! schema-uuid)
(forms-inst/with-attributes (db-attr/required! schema-uuid)) (forms-inst/with-attributes (db-attr/required! schema-uuid))
req)) req))
@ -35,7 +37,7 @@
req-attrs (db-attr/required! schema-uuid) req-attrs (db-attr/required! schema-uuid)
instance (forms-inst/form-data->instance form-data instance (forms-inst/form-data->instance form-data
req-attrs)] req-attrs)]
(domain/create! user-uuid (db/create! user-uuid
schema-uuid schema-uuid
instance) instance)
(resp/redirect (path :instance-list (resp/redirect (path :instance-list
@ -43,13 +45,13 @@
(route-list! schema-uuid req)))) (route-list! schema-uuid req))))
(defn instance! [uuid] (defn instance! [uuid]
(domain/full-instance-by-uuid! uuid)) (db/full-instance-by-uuid! uuid))
(defn route-show! [uuid req] (defn route-show! [uuid req]
(let [user-uuid (-> req :session :uuid) (let [user-uuid (-> req :session :uuid)
instance (assoc (instance! uuid) instance (assoc (instance! uuid)
:starred :starred
(domain/is-starred! uuid (db/is-starred! uuid
user-uuid))] user-uuid))]
(show instance (show instance
(domain-schema/accessible-schemas! user-uuid) (domain-schema/accessible-schemas! user-uuid)
@ -75,20 +77,19 @@
(let [form-data (form/form-data form-def req) (let [form-data (form/form-data form-def req)
form-instance (forms-inst/form-data->instance form-data attrs) form-instance (forms-inst/form-data->instance form-data attrs)
instance (assoc form-instance :uuid uuid)] instance (assoc form-instance :uuid uuid)]
(clojure.pprint/pprint instance) (db/edit! instance (domain/to-revision instance))
(domain/edit! instance)
(resp/redirect (path :instance-show instance))) (resp/redirect (path :instance-show instance)))
(route-show! uuid req)))) (route-show! uuid req))))
(defn route-delete! [uuid] (defn route-delete! [uuid]
(let [schema (domain-schema/find-by-instance! uuid)] (let [schema (domain-schema/find-by-instance! uuid)]
(domain/delete! uuid) (db/delete! uuid)
(resp/redirect (path :instance-list (resp/redirect (path :instance-list
{:schema-uuid (:uuid schema)})))) {:schema-uuid (:uuid schema)}))))
(defn link-form! [schema-uuid] (defn link-form! [schema-uuid]
(forms-inst/link-form (forms-inst/link-form
(domain/find-by-schema! schema-uuid))) (db/find-by-schema! schema-uuid)))
(defn route-link-selection! [uuid schema-uuid req] (defn route-link-selection! [uuid schema-uuid req]
(link-selection (instance! uuid) (link-selection (instance! uuid)
@ -117,28 +118,28 @@
(resp/redirect (path :instance-edit-form {:uuid uuid}))) (resp/redirect (path :instance-edit-form {:uuid uuid})))
(defn route-mark-starred! [uuid req] (defn route-mark-starred! [uuid req]
(domain/mark-starred! uuid (db/mark-starred! uuid
(-> req :session :uuid)) (-> req :session :uuid))
(resp/redirect (path :instance-show {:uuid uuid}))) (resp/redirect (path :instance-show {:uuid uuid})))
(defn route-remove-starred! [uuid req] (defn route-remove-starred! [uuid req]
(domain/remove-starred! uuid (db/remove-starred! uuid
(-> req :session :uuid)) (-> req :session :uuid))
(resp/redirect (path :instance-show {:uuid uuid}))) (resp/redirect (path :instance-show {:uuid uuid})))
(defn route-list-starred! [req] (defn route-list-starred! [req]
(starred (starred
(domain/starred-by-user! (-> req :session :uuid)) (db/starred-by-user! (-> req :session :uuid))
req)) req))
(defn route-bulk-link-selection! [uuid req] (defn route-bulk-link-selection! [uuid req]
(let [user-uuid (-> req :session :uuid)] (let [user-uuid (-> req :session :uuid)]
(bulk-link-selection (domain/full-instance-by-uuid! uuid) (bulk-link-selection (db/full-instance-by-uuid! uuid)
(->> (domain-schema/accessible-schemas! (->> (domain-schema/accessible-schemas!
user-uuid) user-uuid)
(map (fn [schema] (map (fn [schema]
{:schema schema {:schema schema
:instances (domain/find-by-schema! :instances (db/find-by-schema!
(:uuid schema))}))) (:uuid schema))})))
req))) req)))

Loading…
Cancel
Save