From ea7b0078478ba7925f2db3cb1fa038e8a3d85ab8 Mon Sep 17 00:00:00 2001
From: Tim <contact@bytim.eu>
Date: Fri, 30 May 2025 17:09:57 +0200
Subject: Add features to manage recipes in admin interface

---
 src/chef/utils.clj | 21 ++++++++++++++++++++-
 1 file changed, 20 insertions(+), 1 deletion(-)

(limited to 'src/chef/utils.clj')

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)))))
-- 
cgit v1.2.3