time shit and deleting shit and such

integration-tests
Josha von Gizycki 7 years ago
parent 7b4f3aeba5
commit 39c1b06ff5

@ -8,7 +8,8 @@
[gorillalabs/neo4j-clj "1.1.0"]
[hiccup "1.0.5"]
[buddy/buddy-hashers "1.3.0"
:exclusions [commons-codec]]]
:exclusions [commons-codec]]
[clj-time "0.14.4"]]
:plugins [[lein-ring "0.9.7"]]
:ring {:handler wanijo.handler/app}
:profiles {:dev {:dependencies

@ -0,0 +1,17 @@
(ns wanijo.attribute.domain
(:require [clojure.spec.alpha :as spec]
[wanijo.framework.neo4j :as neo4j]))
(neo4j/defquery
findy-by-schema
"MATCH (a:attribute)-->(s:schema)
WHERE s.uuid = {uuid}
RETURN a
ORDER BY a.name")
(defn find-by-schema! [schema-uuid]
(->>
(neo4j/exec-query!
findy-by-schema
{:uuid schema-uuid})
(map :a)))

@ -19,7 +19,7 @@
(-> (redirect "/login")
(assoc :flash :invalid-credentials)))))
(defn login [req]
(defn login! [req]
(view/layout!
:content
[[:h1 "Kama ken"]
@ -37,7 +37,7 @@
(anti-forgery-field))]))
(defroutes routes
(GET "/login" [] login)
(GET "/login" [] login!)
(POST "/login-check" [] login-check!)
(GET "/logout" [] (-> (redirect "/login")
(assoc :session nil))))

@ -1,6 +1,8 @@
(ns wanijo.framework.neo4j
(:require [neo4j-clj.core :as db]
[wanijo.framework.devmode :as devmode])
[wanijo.framework.devmode :as devmode]
[clj-time.format :as time-format]
[clj-time.local :as time-local])
(:import (java.util UUID)))
(def conn
@ -23,10 +25,15 @@
(filter #(> (count %) 0))
(clojure.string/join \newline)))
(defn exec-query [qry params]
(defn exec-query! [qry params]
(with-open [session (db/get-session @conn)]
(devmode/send-to-bar
(str (butiful-query qry)
"<br>---Params---<br>"
params))
(qry session params)))
(defn now-str []
(time-format/unparse
(time-format/formatters :basic-date-time)
(time-local/local-now)))

@ -11,7 +11,7 @@
SET n.uuid = {uuid}")
(defn create-user! [ident pw]
(neo4j/exec-query
(neo4j/exec-query!
create-user
{:ident ident
:pw (hashers/derive pw)

@ -0,0 +1,2 @@
(ns wanijo.framework.time
(:require [clj-time.core :as t]))

@ -36,7 +36,7 @@
(when authed?
[:section.header-content
(btnlink "/schema" "Jaki ijo" "header-content__link")
(btnlink "/logout" "Lape" "header-content__link")])]
(btnlink "/logout" "Lape!" "header-content__link")])]
[:nav (when authed? "nav")]
(vec (concat [:main] content))
[:aside (when authed? "aside")]

@ -6,10 +6,8 @@
(spec/and string? not-empty))
(spec/def ::created-at
(spec/or :int (spec/and int?
#(> % 20000101000000))
:str (spec/and string?
#(re-matches #"\d{4}\d{2}\d{2}\d{2}\d{2}\d{2}" %))))
(spec/and string?
#(re-matches #"\d{4}\d{2}\d{2}T\d{2}\d{2}\d{2}\.\d{3}Z" %)))
(neo4j/defquery
all-created-by
@ -19,10 +17,11 @@
ORDER BY s.name")
(defn all-created-by! [user-uuid]
(map :s
(neo4j/exec-query
all-created-by
{:uuid user-uuid})))
(->>
(neo4j/exec-query!
all-created-by
{:uuid user-uuid})
(map :s)))
(neo4j/defquery
create-new
@ -31,28 +30,63 @@
CREATE (s:schema)-[:created_by]->(u)
SET s.name = {name}
SET s.uuid = {s_uuid}
SET s.created_at = {created_at}
RETURN s")
(defn create-new! [name user-uuid]
(->>
(neo4j/exec-query
(neo4j/exec-query!
create-new
{:u_uuid user-uuid
:name name
:s_uuid (neo4j/uuid)})
:s_uuid (neo4j/uuid)
:created_at (neo4j/now-str)})
first
:uuid))
(neo4j/defquery
find-by-id!
find-by-uuid
"MATCH (s:schema)
WHERE s.uuid = {uuid}
RETURN s")
(defn find-by-uuid! [uuid]
(->>
(neo4j/exec-query
find-by-id!
(neo4j/exec-query!
find-by-uuid
{:uuid uuid})
first
:s))
(neo4j/defquery
schema-creator
"MATCH (s:schema)-->(u:user)
WHERE s.uuid = {uuid}
RETURN u.uuid as uuid")
(defn find-schema-creator! [uuid]
(->>
(neo4j/exec-query!
schema-creator
{:uuid uuid})
first
:uuid))
(defn can-user-modify? [schema-uuid user-uuid]
(let [creator (find-schema-creator! schema-uuid)]
(= creator user-uuid)))
(neo4j/defquery
delete
"MATCH (s:schema)
WHERE s.uuid = {uuid}
OPTIONAL MATCH (s)--(a:attribute)
DELETE a
WITH s
MATCH (s)-[c]-()
DELETE c, s")
(defn delete! [uuid]
(neo4j/exec-query!
delete
{:uuid uuid}))

@ -1,10 +1,11 @@
(ns wanijo.schema.routes
(:require [compojure.core :refer [defroutes GET POST]]
(:require [compojure.core :refer [defroutes GET POST DELETE]]
[ring.util.response :as resp]
[wanijo.framework.view :as view]
[wanijo.framework.form :as form]
[wanijo.schema.domain :as domain]
[wanijo.schema.view :as view-schema]))
[wanijo.schema.view :as view-schema]
[wanijo.attribute.domain :as attr-domain]))
(defn new! [req]
(if (form/valid? view-schema/new-form req)
@ -16,12 +17,20 @@
(view-schema/overview! req)))
(defn show-schema! [uuid session]
(println uuid session)
(view-schema/show-schema!
(domain/find-by-uuid! uuid)
(attr-domain/find-by-schema! uuid)
session))
(defn delete-schema! [uuid session]
(if (domain/can-user-modify? uuid (:uuid session))
(do
(domain/delete! uuid)
(resp/redirect "/schema"))
{:status 403}))
(defroutes routes
(GET "/schema" [] view-schema/overview!)
(GET "/schema/:uuid" [uuid :as req] (show-schema! uuid (:session req)))
(POST "/schema/new" [] new!))
(POST "/schema/new" [] new!)
(DELETE "/schema/:uuid/delete" [uuid :as req] (delete-schema! uuid (:session req))))

@ -8,7 +8,7 @@
(def new-form
{:fields {:schema-name {:label "Nimi"
:required true
:spec :wanijo.domain.schema/name}}})
:spec ::domain/name}}})
(defn overview! [req]
(let [session (:session req)
@ -37,8 +37,19 @@
(hform/submit-button "Pali")
(anti-forgery-field))])))
(defn show-schema! [schema session]
(defn show-schema! [schema attrs session]
(view/layout!
:session session
:content
[[:h1 "Jaki ijo " (:name schema)]]))
[[:h1 "Jaki ijo " (:name schema)]
(hform/form-to
[:post "/schema/edit"])
[:h2 "Lili wan e jaki ijo"]
[:ul
(for [attr attrs]
[:li (:name attr)])]
[:h2 "Mute pali"]
(hform/form-to
[:delete (str "/schema/" (:uuid schema) "/delete")]
(anti-forgery-field)
(hform/submit-button "Pakala!"))]))

@ -9,7 +9,7 @@
(defn find! [ident]
(->>
(neo4j/exec-query
(neo4j/exec-query!
find-user
{:ident ident})
first

Loading…
Cancel
Save