instance deletion

integration-tests
Josha von Gizycki 6 years ago
parent b8339001f0
commit 56ed79acb3

@ -95,7 +95,6 @@
p.value = {value}")
(defn edit! [instance]
(clojure.pprint/pprint instance)
(let [prop-tuples (map #(vector edit-property
{:uuid (:uuid % (neo4j/uuid))
:now (neo4j/now-str)
@ -109,3 +108,14 @@
:name (:name instance)
:updated_at (neo4j/now-str)}]]
prop-tuples))))
(neo4j/defquery delete
"MATCH (i:instance {uuid:{uuid}}),
(i)-[ic:of]->(s:schema)
OPTIONAL MATCH
(p:property)-[pc:of]->(i),
(p)-[pac:of]->(a:attribute)
DELETE pac, pc, ic, p, i")
(defn delete! [uuid]
(neo4j/exec-query! delete {:uuid uuid}))

@ -63,12 +63,19 @@
(resp/redirect (path :instance-show instance)))
(show! uuid req))))
(defn delete! [uuid req]
(let [schema (domain-schema/find-by-instance! uuid)]
(domain/delete! uuid)
(resp/redirect (path :instance-list
{:schema-uuid (:uuid schema)}))))
(defroutes routes
(wrap-routes (GET (register! :instance-list "/instance/list/:schema-uuid")
(wrap-routes
(GET (register! :instance-list "/instance/list/:schema-uuid")
[schema-uuid :as req]
(list! schema-uuid req))
(middleware-schema/wrap-allowed-to-read
#(get-in % [:params :schema-uuid])))
(let [schema-fn #(get-in % [:params :schema-uuid])]
(middleware-schema/wrap-allowed-to-read schema-fn)))
(POST (register! :instance-new "/instance/new") []
new!)
(GET (register! :instance-show "/instance/:uuid")
@ -76,4 +83,7 @@
(show! uuid req))
(POST (register! :instance-edit "/instance/:uuid")
[uuid :as req]
(edit! uuid req)))
(edit! uuid req))
(DELETE (register! :instance-delete "/instance/:uuid")
[uuid :as req]
(delete! uuid req)))

@ -41,4 +41,7 @@
[[:h1 (:name instance)]
(hform/form-to [:post (path :instance-edit instance)]
(form/render-widgets form form-data req)
(hform/submit-button "Edit!"))]))
(hform/submit-button "Edit!"))
(hform/form-to [:delete ""]
(anti-forgery-field)
(view/delete-btn))]))

@ -232,3 +232,13 @@
{:uuid uuid}]
[create-schema-assignments
{:uuid uuid :schemas schemas}]))
(neo4j/defquery find-by-instance
"MATCH (i:instance {uuid:{uuid}})-[:of]->(s:schema)
RETURN s")
(defn find-by-instance! [uuid]
(-> find-by-instance
(neo4j/exec-query! {:uuid uuid})
first
:s))

Loading…
Cancel
Save