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.clj21
1 files changed, 20 insertions, 1 deletions
diff --git a/src/chef/utils.clj b/src/chef/utils.clj
index f909c52..1ea5136 100644
--- a/src/chef/utils.clj
+++ b/src/chef/utils.clj
@@ -1,5 +1,9 @@
(ns chef.utils
- (:require [ring.util.response :as ruresp]))
+ (:require [chef.database :as cdb]
+ [honey.sql :as sql]
+ [next.jdbc :as jdbc]
+ [ring.util.response :as ruresp]
+ [clojure.string :as cstr]))
(defn gen-page [title & content]
[:html
@@ -16,3 +20,18 @@
~(-> (ruresp/response "Unauthorized.")
(ruresp/status 302)
(ruresp/header "Location" "/auth"))))
+
+(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)))))