Implement profile validation
This commit is contained in:
@@ -30,10 +30,22 @@
|
||||
"\n"
|
||||
(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]
|
||||
(->> store
|
||||
keys
|
||||
(map (fn [category] [category (filter #(.contains profile (:key %)) (get store category))]))
|
||||
(filter #(not (empty? (second %))))
|
||||
(map #(produce-category (first %) (second %) nights i18n))
|
||||
(clojure.string/join "\n\n")))
|
||||
(do
|
||||
(validate-profile store profile)
|
||||
(->> store
|
||||
keys
|
||||
(map (fn [category] [category (filter #(.contains profile (:key %)) (get store category))]))
|
||||
(filter #(not (empty? (second %))))
|
||||
(map #(produce-category (first %) (second %) nights i18n))
|
||||
(clojure.string/join "\n\n"))))
|
||||
Reference in New Issue
Block a user