|
|
|
@ -1,5 +1,9 @@
|
|
|
|
|
(ns wanijo.schema.routes
|
|
|
|
|
(:require [compojure.core :refer [defroutes GET]]
|
|
|
|
|
(:require [compojure.core :refer [defroutes GET POST]]
|
|
|
|
|
[ring.util.anti-forgery :refer [anti-forgery-field]]
|
|
|
|
|
[ring.util.response :as resp]
|
|
|
|
|
[hiccup.form :as hform]
|
|
|
|
|
[clojure.spec.alpha :as spec]
|
|
|
|
|
[wanijo.domain.schema :as domain-schemas]
|
|
|
|
|
[wanijo.view :as view]))
|
|
|
|
|
|
|
|
|
@ -10,7 +14,8 @@
|
|
|
|
|
(view/layout!
|
|
|
|
|
:session session
|
|
|
|
|
:content
|
|
|
|
|
[[:table
|
|
|
|
|
[[:h1 "Ali jaki ijo"]
|
|
|
|
|
[:table
|
|
|
|
|
[:thead
|
|
|
|
|
[:tr
|
|
|
|
|
[:th "Nimi"]
|
|
|
|
@ -19,7 +24,29 @@
|
|
|
|
|
(for [schema schemas]
|
|
|
|
|
[:tr
|
|
|
|
|
[:td (:name schema)]
|
|
|
|
|
[:td (:created_at schema)]])]]])))
|
|
|
|
|
[:td (:created_at schema)]])]]
|
|
|
|
|
[:h1 "Pali sin e jaki ijo"]
|
|
|
|
|
(hform/form-to
|
|
|
|
|
[:post "/schema/new"]
|
|
|
|
|
(view/spec-to-errmsg ::new-schema req)
|
|
|
|
|
(hform/label "name" "Nimi")
|
|
|
|
|
(hform/text-field {:required "required"}
|
|
|
|
|
"schema-name"
|
|
|
|
|
(get-in req [:params :schema-name]))
|
|
|
|
|
(hform/submit-button "Kama")
|
|
|
|
|
(anti-forgery-field))])))
|
|
|
|
|
|
|
|
|
|
(spec/def ::schema-name
|
|
|
|
|
(spec/and some? string? not-empty))
|
|
|
|
|
|
|
|
|
|
(spec/def ::new-schema
|
|
|
|
|
(spec/keys :req-un [::schema-name]))
|
|
|
|
|
|
|
|
|
|
(defn- new! [req]
|
|
|
|
|
(if (spec/valid? ::new-schema (:params req))
|
|
|
|
|
(resp/redirect "/schema")
|
|
|
|
|
(overview! req)))
|
|
|
|
|
|
|
|
|
|
(defroutes schema-routes
|
|
|
|
|
(GET "/schema" [] overview!))
|
|
|
|
|
(GET "/schema" [] overview!)
|
|
|
|
|
(POST "/schema/new" [] new!))
|
|
|
|
|