diff options
author | Tim <contact@bytim.eu> | 2025-06-14 11:49:28 +0200 |
---|---|---|
committer | Tim <contact@bytim.eu> | 2025-06-14 11:49:28 +0200 |
commit | 8e23d9dade945f87f5fc7fb15042a53a7eeb9a9e (patch) | |
tree | c0f5b6587b6f9f0b591b395c69ad7da08717a30b /src/chef/frontend/visitor/search.clj | |
parent | 229299146376a2b847f4fe3f331efbd26c0abc70 (diff) | |
download | chef-8e23d9dade945f87f5fc7fb15042a53a7eeb9a9e.tar.xz chef-8e23d9dade945f87f5fc7fb15042a53a7eeb9a9e.zip |
Refactor project structure
Diffstat (limited to 'src/chef/frontend/visitor/search.clj')
-rw-r--r-- | src/chef/frontend/visitor/search.clj | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/src/chef/frontend/visitor/search.clj b/src/chef/frontend/visitor/search.clj new file mode 100644 index 0000000..7a2db93 --- /dev/null +++ b/src/chef/frontend/visitor/search.clj @@ -0,0 +1,38 @@ +(ns chef.frontend.visitor.search + (:require [chef.utils :as cutils] + [clojure.string :as cstr] + [hiccup2.core :as html] + [ring.util.response :as ruresp] + + [chef.logic.categories :as clcategories] + [chef.logic.recipes :as clrecipes])) + +(defn render [query category] + [:table + [:tr + [:th "Rezept"] + [:th "Kategorie"]] + (for [recipe (clrecipes/get-all-recipes) + :let [recipe-category (clcategories/get-category (:recipes/category recipe))]] + (when (or (= category -1) + (and (cstr/includes? (-> recipe + :recipes/title + cstr/lower-case) + query) + (some #(= (:categories/id %) category) + (clcategories/get-parents recipe-category)))) + [:tr + [:td + [:b [:a {:href (str "/recipes/" (:recipes/id recipe))} (:recipes/title recipe)]]] + [:td + (-> (:recipes/category recipe) + clcategories/get-category + clcategories/generate-path)]]))]) + +(defn handler [req] + (if-let [query (get-in req [:params "query"])] + (-> (render query (or (cutils/s->int-or-nil (get-in req [:params "category"])) -1)) + html/html + str + ruresp/response) + (ruresp/bad-request "No search query provide."))) |