summaryrefslogtreecommitdiff
path: root/src/chef/utils.clj
diff options
context:
space:
mode:
Diffstat (limited to 'src/chef/utils.clj')
-rw-r--r--src/chef/utils.clj31
1 files changed, 18 insertions, 13 deletions
diff --git a/src/chef/utils.clj b/src/chef/utils.clj
index 1ea5136..c2c6bc1 100644
--- a/src/chef/utils.clj
+++ b/src/chef/utils.clj
@@ -21,17 +21,22 @@
(ruresp/status 302)
(ruresp/header "Location" "/auth"))))
+(defn category-parents [category]
+ (loop [parents (list)
+ category category]
+ (let [updated-parents (conj parents category)]
+ (if (not= -1 (:categories/parent category))
+ (recur updated-parents
+ (->> {:select [:*]
+ :from [:categories]
+ :where [:= :id (:categories/parent category)]}
+ sql/format
+ (jdbc/execute! @cdb/db)
+ first))
+ updated-parents))))
+
(defn category-path [category]
- (cstr/join " > "
- (loop [path (list)
- category category]
- (let [new-path (conj path (:categories/name category))]
- (if (some? (:categories/parent category))
- (recur new-path
- (->> {:select [:*]
- :from [:categories]
- :where [:= :id (:categories/parent category)]}
- sql/format
- (jdbc/execute! @cdb/db)
- first))
- new-path)))))
+ (->> category
+ category-parents
+ (map #(:categories/name %))
+ (cstr/join " > ")))