|
|
@ -3,25 +3,36 @@
|
|
|
|
[ring.util.response :as resp]
|
|
|
|
[ring.util.response :as resp]
|
|
|
|
[wanijo.framework.view :as view]
|
|
|
|
[wanijo.framework.view :as view]
|
|
|
|
[wanijo.framework.form :as form]
|
|
|
|
[wanijo.framework.form :as form]
|
|
|
|
[wanijo.framework.routing :refer [register!]]
|
|
|
|
[wanijo.framework.routing :refer [register! path]]
|
|
|
|
[wanijo.schema.domain :as domain]
|
|
|
|
[wanijo.schema.domain :as domain]
|
|
|
|
[wanijo.schema.view :as view-schema]
|
|
|
|
[wanijo.schema.view :as view-schema]
|
|
|
|
[wanijo.attribute.domain :as attr-domain]))
|
|
|
|
[wanijo.attribute.domain :as domain-attr]))
|
|
|
|
|
|
|
|
|
|
|
|
(defn new! [req]
|
|
|
|
(defn new! [req]
|
|
|
|
(if (form/valid? view-schema/new-form req)
|
|
|
|
(if (form/valid? view-schema/form req)
|
|
|
|
(do
|
|
|
|
(do
|
|
|
|
(domain/create-new!
|
|
|
|
(domain/create-new!
|
|
|
|
(get-in req [:params :schema-name])
|
|
|
|
(get-in req [:params :name])
|
|
|
|
(get-in req [:session :uuid]))
|
|
|
|
(get-in req [:session :uuid]))
|
|
|
|
(resp/redirect "/schema"))
|
|
|
|
(resp/redirect (path :schema-overview)))
|
|
|
|
(view-schema/overview! req)))
|
|
|
|
(view-schema/overview! req)))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
(defn edit! [req]
|
|
|
|
|
|
|
|
(let [uuid (get-in req [:params :uuid])]
|
|
|
|
|
|
|
|
(if (form/valid? view-schema/form req)
|
|
|
|
|
|
|
|
(do
|
|
|
|
|
|
|
|
(domain/edit! (:params req))
|
|
|
|
|
|
|
|
(resp/redirect (path :schema-show (:params req))))
|
|
|
|
|
|
|
|
(view-schema/show-schema!
|
|
|
|
|
|
|
|
(domain/find-by-uuid! uuid)
|
|
|
|
|
|
|
|
(domain-attr/find-by-schema! uuid)
|
|
|
|
|
|
|
|
req))))
|
|
|
|
|
|
|
|
|
|
|
|
(defn delete-schema! [uuid session]
|
|
|
|
(defn delete-schema! [uuid session]
|
|
|
|
(if (domain/can-user-modify? uuid (:uuid session))
|
|
|
|
(if (domain/can-user-modify? uuid (:uuid session))
|
|
|
|
(do
|
|
|
|
(do
|
|
|
|
(domain/delete! uuid)
|
|
|
|
(domain/delete! uuid)
|
|
|
|
(resp/redirect "/schema"))
|
|
|
|
(resp/redirect (path :schema-overview)))
|
|
|
|
{:status 403}))
|
|
|
|
{:status 403}))
|
|
|
|
|
|
|
|
|
|
|
|
(defroutes routes
|
|
|
|
(defroutes routes
|
|
|
@ -32,11 +43,14 @@
|
|
|
|
[uuid :as req]
|
|
|
|
[uuid :as req]
|
|
|
|
(view-schema/show-schema!
|
|
|
|
(view-schema/show-schema!
|
|
|
|
(domain/find-by-uuid! uuid)
|
|
|
|
(domain/find-by-uuid! uuid)
|
|
|
|
(attr-domain/find-by-schema! uuid)
|
|
|
|
(domain-attr/find-by-schema! uuid)
|
|
|
|
req))
|
|
|
|
req))
|
|
|
|
(POST (register! :schema-new "/schema/new")
|
|
|
|
(POST (register! :schema-new "/schema/new")
|
|
|
|
[]
|
|
|
|
[]
|
|
|
|
new!)
|
|
|
|
new!)
|
|
|
|
|
|
|
|
(POST (register! :schema-edit "/schema/edit")
|
|
|
|
|
|
|
|
[]
|
|
|
|
|
|
|
|
edit!)
|
|
|
|
(DELETE (register! :schema-delete "/schema/:uuid")
|
|
|
|
(DELETE (register! :schema-delete "/schema/:uuid")
|
|
|
|
[uuid :as req]
|
|
|
|
[uuid :as req]
|
|
|
|
(delete-schema! uuid (:session req))))
|
|
|
|
(delete-schema! uuid (:session req))))
|
|
|
|