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