Implement profile validation
This commit is contained in:
@@ -30,10 +30,22 @@
|
|||||||
"\n"
|
"\n"
|
||||||
(produce-items items nights i18n))))
|
(produce-items items nights i18n))))
|
||||||
|
|
||||||
|
(defn validate-profile [store profile]
|
||||||
|
(let [all-items (->> store
|
||||||
|
vals
|
||||||
|
flatten
|
||||||
|
(map :key))
|
||||||
|
missing-items (remove (set all-items) profile)
|
||||||
|
missing-items-str (clojure.string/join ", " missing-items)]
|
||||||
|
(when (not (empty? missing-items))
|
||||||
|
(throw (Exception. (str "The following keys are found in the profile, but they are not defined in store: " missing-items-str))))))
|
||||||
|
|
||||||
(defn produce [store profile nights i18n]
|
(defn produce [store profile nights i18n]
|
||||||
(->> store
|
(do
|
||||||
keys
|
(validate-profile store profile)
|
||||||
(map (fn [category] [category (filter #(.contains profile (:key %)) (get store category))]))
|
(->> store
|
||||||
(filter #(not (empty? (second %))))
|
keys
|
||||||
(map #(produce-category (first %) (second %) nights i18n))
|
(map (fn [category] [category (filter #(.contains profile (:key %)) (get store category))]))
|
||||||
(clojure.string/join "\n\n")))
|
(filter #(not (empty? (second %))))
|
||||||
|
(map #(produce-category (first %) (second %) nights i18n))
|
||||||
|
(clojure.string/join "\n\n"))))
|
||||||
Reference in New Issue
Block a user