From 8e23d9dade945f87f5fc7fb15042a53a7eeb9a9e Mon Sep 17 00:00:00 2001 From: Tim Date: Sat, 14 Jun 2025 11:49:28 +0200 Subject: Refactor project structure --- src/chef/pages/recipe.clj | 77 ----------------------------------------------- 1 file changed, 77 deletions(-) delete mode 100644 src/chef/pages/recipe.clj (limited to 'src/chef/pages/recipe.clj') diff --git a/src/chef/pages/recipe.clj b/src/chef/pages/recipe.clj deleted file mode 100644 index be88b2d..0000000 --- a/src/chef/pages/recipe.clj +++ /dev/null @@ -1,77 +0,0 @@ -(ns chef.pages.recipe - (: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]) - (:import java.io.File)) - -(defn- render [portions recipe] - (cutils/gen-page (str "chef - " (:recipes/title recipe)) - [:div {:style {:margin-left "1em"}} - [:div - [:h1 {:style {:display :inline-block - :margin-right "0.5em"}} - (:recipes/title recipe)] - [:i (str "(" (cutils/category-path (->> {:select [:*] - :from [:categories] - :where [:= :id (:recipes/category recipe)]} - sql/format - (jdbc/execute! @cdb/db) - first)) ")")]] - (when (some? (cutils/get-thumbnail-file recipe)) - [:img {:src (str "/recipes/" (:recipes/id recipe) "/thumbnail") - :width "50%"}]) - [:h2 - "Zutaten pro " - [:input {:type :number - :value portions - :style {:width "3em" - :display :inline-block} - "_" "on change go to url `?portions=${value of me}`"}] - (condp = (:recipes/unit recipe) - 0 " Portion(en)" - 1 " Person(en)" - "") - ":"] - [:ul (for [ingredient (-> recipe - :recipes/ingredients - cutils/parse-ingredients)] - [:li - [:b (:description ingredient)] ": " - (* (:amount ingredient) portions) - (:unit ingredient)])] - [:h2 "Zubereitung"] - (->> (:recipes/preparation recipe) - cstr/split-lines - (map #(if (cstr/blank? %) - [:br] - [:p %])))])) - -(defn handler [req] - (->> {:select [:*] - :from [:recipes] - :where [:= :id (get-in req [:path-params :id])]} - sql/format - (jdbc/execute! @cdb/db) - first - (render (or (try (Integer/parseInt (get-in req [:params "portions"])) - (catch Exception _ nil)) - 1)) - html/html - str - ruresp/response)) - -(defn thumbnail-handler [req] - (if-let [id (get-in req [:path-params :id])] - (when-let [thumbnail-file (->> {:select [:*] - :from [:recipes] - :where [:= :id id]} - sql/format - (jdbc/execute! @cdb/db) - first - cutils/get-thumbnail-file)] - (ruresp/file-response (.getPath ^File thumbnail-file))) - (ruresp/bad-request "Bad request."))) -- cgit v1.2.3