From bf38eddb4a6931560183c143f0c5eed3aec528e5 Mon Sep 17 00:00:00 2001 From: Josha von Gizycki Date: Sat, 4 Aug 2018 23:42:15 +0200 Subject: [PATCH] hmm, some fixes --- src/wanijo/attribute/domain.clj | 22 +++++++++++++++++++++- src/wanijo/attribute/routes.clj | 21 +++++++++++++++++++-- src/wanijo/handler.clj | 4 +++- src/wanijo/schema/domain.clj | 2 +- 4 files changed, 44 insertions(+), 5 deletions(-) diff --git a/src/wanijo/attribute/domain.clj b/src/wanijo/attribute/domain.clj index 5c17b4e..1329682 100644 --- a/src/wanijo/attribute/domain.clj +++ b/src/wanijo/attribute/domain.clj @@ -10,7 +10,9 @@ string? #(some #{"date" "file" "string" "text"} %))) -(spec/def ::required boolean?) +(spec/def ::required + (spec/or :bool-val boolean? + :nil nil?)) (neo4j/defquery findy-by-schema @@ -25,3 +27,21 @@ findy-by-schema {:uuid schema-uuid}) (map :a))) + +(neo4j/defquery create-new + "MATCH (u:user)--(s:schema) + WHERE u.uuid = {user_uuid} + AND s.uuid = {schema_uuid} + CREATE (a:attribute) + CREATE (a)-[:created_by]->(u) + CREATE (a)-[:of]->(s) + SET a.type = {type} + SET a.name = {name}") + +(defn create-new! [name type schema-uuid user-uuid] + (neo4j/exec-query! + create-new + {:user_uuid user-uuid + :schem_uuid schema-uuid + :type type + :name name})) diff --git a/src/wanijo/attribute/routes.clj b/src/wanijo/attribute/routes.clj index e233417..99c0cc6 100644 --- a/src/wanijo/attribute/routes.clj +++ b/src/wanijo/attribute/routes.clj @@ -2,9 +2,26 @@ (:require [compojure.core :refer [defroutes GET POST]] [ring.util.response :as resp] [wanijo.framework.form :as form] - [wanijo.framework.routing :refer [register]])) + [wanijo.framework.routing :refer [register path]] + [wanijo.attribute.domain :as domain] + [wanijo.schema.view :as view-schema] + [wanijo.schema.domain :as domain-schema])) -(defn new! [req]) +(defn new! [req] + (let [schema-uuid (get-in req [:params :schema])] + (if (form/valid? view-schema/new-attr-form req) + (do + (domain/create-new! + (get-in req [:params :name]) + (get-in req [:params :type]) + schema-uuid + (get-in req [:session :uuid])) + (resp/redirect (path :schema-show + schema-uuid))) + (view-schema/show-schema! + (domain-schema/find-by-uuid! schema-uuid) + (domain/find-by-schema! schema-uuid) + req)))) (register :attribute-new "/attribute/new") diff --git a/src/wanijo/handler.clj b/src/wanijo/handler.clj index dd381c5..c83bffa 100644 --- a/src/wanijo/handler.clj +++ b/src/wanijo/handler.clj @@ -9,6 +9,7 @@ [wanijo.home.routes :as home-routes] [wanijo.schema.routes :as schema-routes] [wanijo.user.routes :as user-routes] + [wanijo.attribute.routes :as attr-routes] [wanijo.framework.auth :as auth] [wanijo.framework.devmode :as devmode] [wanijo.framework.routing :refer [path]])) @@ -24,7 +25,8 @@ (wrap-login-redirect (routes home-routes/routes schema-routes/routes - user-routes/routes)) + user-routes/routes + attr-routes/routes)) (route/not-found "Not Found")) (def app diff --git a/src/wanijo/schema/domain.clj b/src/wanijo/schema/domain.clj index 332c468..d25094a 100644 --- a/src/wanijo/schema/domain.clj +++ b/src/wanijo/schema/domain.clj @@ -11,7 +11,7 @@ (neo4j/defquery all-created-by - "MATCH (s:schema)-[:created_by]->(u:user) + "MATCH (s:schema)-->(u:user) WHERE u.uuid = {uuid} RETURN s ORDER BY s.name")