Implement profile validation

This commit is contained in:
2024-04-13 18:22:38 +02:00
parent 5f55559eae
commit dd63cee18f

View File

@@ -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"))))