From ffb5d0b740e3fa23143ad89dab29a44d5b0acd34 Mon Sep 17 00:00:00 2001 From: Tim Date: Sat, 31 May 2025 17:03:51 +0200 Subject: Add real data to home page + add search logic + add recipe pages --- src/chef/utils.clj | 31 ++++++++++++++++++------------- 1 file changed, 18 insertions(+), 13 deletions(-) (limited to 'src/chef/utils.clj') 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 " > "))) -- cgit v1.2.3