summaryrefslogtreecommitdiff
path: root/src/chef/components
diff options
context:
space:
mode:
authorTim <contact@bytim.eu>2025-06-14 11:49:28 +0200
committerTim <contact@bytim.eu>2025-06-14 11:49:28 +0200
commit8e23d9dade945f87f5fc7fb15042a53a7eeb9a9e (patch)
treec0f5b6587b6f9f0b591b395c69ad7da08717a30b /src/chef/components
parent229299146376a2b847f4fe3f331efbd26c0abc70 (diff)
downloadchef-8e23d9dade945f87f5fc7fb15042a53a7eeb9a9e.tar.xz
chef-8e23d9dade945f87f5fc7fb15042a53a7eeb9a9e.zip
Refactor project structure
Diffstat (limited to 'src/chef/components')
-rw-r--r--src/chef/components/search.clj49
1 files changed, 0 insertions, 49 deletions
diff --git a/src/chef/components/search.clj b/src/chef/components/search.clj
deleted file mode 100644
index e428a23..0000000
--- a/src/chef/components/search.clj
+++ /dev/null
@@ -1,49 +0,0 @@
-(ns chef.components.search
- (:require [chef.database :as cdb]
- [chef.utils :as cutils]
- [clojure.string :as cstr]
- [hiccup2.core :as html]
- [honey.sql :as sql]
- [next.jdbc :as jdbc]
- [ring.util.response :as ruresp]))
-
-(defn render [query category]
- [:table
- [:tr
- [:th "Rezept"]
- [:th "Kategorie"]]
- (for [recipe (jdbc/execute! @cdb/db
- (sql/format {:select [:*]
- :from [:recipes]}))
- :let [recipe-category (->> {:select [:*]
- :from [:categories]
- :where [:= :id (:recipes/category recipe)]}
- sql/format
- (jdbc/execute! @cdb/db)
- first)]]
- (when (or (= category -1)
- (and (cstr/includes? (-> recipe
- :recipes/title
- cstr/lower-case)
- query)
- (some #(= (:categories/id %) category)
- (cutils/category-parents recipe-category))))
- [:tr
- [:td
- [:b [:a {:href (str "/recipes/" (:recipes/id recipe))} (:recipes/title recipe)]]]
- [:td
- (cutils/category-path (->> {:select [:*]
- :from [:categories]
- :where [:= :id (:recipes/category recipe)]}
- sql/format
- (jdbc/execute! @cdb/db)
- first))]]))])
-
-(defn handler [req]
- (if-let [query (get-in req [:params "query"])]
- (-> (render query (try (Integer/parseInt (get-in req [:params "category"]))
- (catch Exception _ -1)))
- html/html
- str
- ruresp/response)
- (ruresp/bad-request "No search query provide.")))