|
|
|
@ -1,13 +1,16 @@
|
|
|
|
|
(ns wanijo.instance.routes
|
|
|
|
|
(:require [compojure.core :refer [defroutes GET POST DELETE]]
|
|
|
|
|
(:require [compojure.core :refer [defroutes wrap-routes
|
|
|
|
|
GET POST DELETE]]
|
|
|
|
|
[ring.util.response :as resp]
|
|
|
|
|
[formulare.core :as form]
|
|
|
|
|
[wanijo.instance
|
|
|
|
|
[view :as view]
|
|
|
|
|
[domain :as domain]
|
|
|
|
|
[forms :as forms-inst]]
|
|
|
|
|
[wanijo.schema
|
|
|
|
|
[domain :as domain-schema]
|
|
|
|
|
[middleware :as middleware-schema]]
|
|
|
|
|
[wanijo.framework.routing :refer [register! path]]
|
|
|
|
|
[wanijo.schema.domain :as domain-schema]
|
|
|
|
|
[wanijo.attribute.domain :as domain-attr]))
|
|
|
|
|
|
|
|
|
|
(defn list! [schema-uuid req]
|
|
|
|
@ -31,22 +34,46 @@
|
|
|
|
|
(:params req))))
|
|
|
|
|
(list! schema-uuid req))))
|
|
|
|
|
|
|
|
|
|
(defn show! [uuid req]
|
|
|
|
|
(let [instance (assoc (domain/find-by-uuid! uuid)
|
|
|
|
|
(defn form! [uuid]
|
|
|
|
|
(forms-inst/with-attributes
|
|
|
|
|
(domain-attr/find-by-instance! uuid)))
|
|
|
|
|
|
|
|
|
|
(defn instance! [uuid]
|
|
|
|
|
(assoc (domain/find-by-uuid! uuid)
|
|
|
|
|
:properties
|
|
|
|
|
(domain/find-properties! uuid))
|
|
|
|
|
(domain/find-properties! uuid)))
|
|
|
|
|
|
|
|
|
|
(defn show! [uuid req]
|
|
|
|
|
(let [instance (instance! uuid)
|
|
|
|
|
attrs (domain-attr/find-by-instance! uuid)]
|
|
|
|
|
(view/show! instance
|
|
|
|
|
(forms-inst/with-attributes attrs)
|
|
|
|
|
(form! uuid)
|
|
|
|
|
(forms-inst/instance->form-data instance)
|
|
|
|
|
req)))
|
|
|
|
|
|
|
|
|
|
(defn edit! [uuid req]
|
|
|
|
|
(let [form-def (form! uuid)
|
|
|
|
|
instance (instance! uuid)]
|
|
|
|
|
(if (form/valid? form-def req)
|
|
|
|
|
(let [form-data (form/form-data form-def req)
|
|
|
|
|
attrs (domain-attr/find-by-instance! uuid)
|
|
|
|
|
form-instance (forms-inst/form-data->instance form-data attrs)
|
|
|
|
|
instance (assoc form-instance :uuid uuid)]
|
|
|
|
|
(domain/edit! instance)
|
|
|
|
|
(resp/redirect (path :instance-show instance)))
|
|
|
|
|
(show! uuid req))))
|
|
|
|
|
|
|
|
|
|
(defroutes routes
|
|
|
|
|
(GET (register! :instance-list "/instance/list/:schema-uuid")
|
|
|
|
|
(wrap-routes (GET (register! :instance-list "/instance/list/:schema-uuid")
|
|
|
|
|
[schema-uuid :as req]
|
|
|
|
|
(list! schema-uuid req))
|
|
|
|
|
(middleware-schema/wrap-allowed-to-read
|
|
|
|
|
#(get-in % [:params :schema-uuid])))
|
|
|
|
|
(POST (register! :instance-new "/instance/new") []
|
|
|
|
|
new!)
|
|
|
|
|
(GET (register! :instance-show "/instance/:uuid")
|
|
|
|
|
[uuid :as req]
|
|
|
|
|
(show! uuid req)))
|
|
|
|
|
(show! uuid req))
|
|
|
|
|
(POST (register! :instance-edit "/instance/:uuid")
|
|
|
|
|
[uuid :as req]
|
|
|
|
|
(edit! uuid req)))
|
|
|
|
|