diff --git a/src/wanijo/instance/domain.clj b/src/wanijo/instance/domain.clj index f5e665a..d9aee88 100644 --- a/src/wanijo/instance/domain.clj +++ b/src/wanijo/instance/domain.clj @@ -20,8 +20,10 @@ {:uuid schema-uuid}))) (neo4j/defquery create-instance - "MATCH (s:schema {uuid:{schema_uuid}}) - CREATE (i:instance {uuid:{uuid}})-[:of]->(s) + "MATCH (s:schema {uuid:{schema_uuid}}), + (u:user {uuid:{user_uuid}}) + CREATE (i:instance {uuid:{uuid}})-[:of]->(s), + (i)-[:created_by]->(u) SET i.name = {name}, i.created_at = {created_at}, i.updated_at = {created_at}") @@ -35,14 +37,15 @@ p.created_at = {created_at}, p.updated_at = {updated_at}") -(defn create! [schema-uuid instance] +(defn create! [user-uuid schema-uuid instance] (let [instance-uuid (neo4j/uuid) now (neo4j/now-str) instance-tuple [create-instance {:schema_uuid schema-uuid :name (:name instance) :uuid instance-uuid - :created_at now}] + :created_at now + :user_uuid user-uuid}] prop-tuples (for [{:keys [attribute value]} (:properties instance)] [create-property {:uuid instance-uuid diff --git a/src/wanijo/instance/routes.clj b/src/wanijo/instance/routes.clj index e281bfb..b256533 100644 --- a/src/wanijo/instance/routes.clj +++ b/src/wanijo/instance/routes.clj @@ -21,6 +21,7 @@ (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) form-def (forms-inst/with-attributes req-attrs)] (if (form/valid? form-def req) @@ -28,7 +29,8 @@ req-attrs (domain-attr/required! schema-uuid) instance (forms-inst/form-data->instance form-data req-attrs)] - (domain/create! schema-uuid + (domain/create! user-uuid + schema-uuid instance) (resp/redirect (path :instance-list (:params req))))