diff --git a/src/snippets/infra/api.clj b/src/snippets/infra/api.clj index 5f2c6fe..ca63693 100644 --- a/src/snippets/infra/api.clj +++ b/src/snippets/infra/api.clj @@ -2,6 +2,7 @@ (:require [ring.adapter.jetty :as jetty] [clojure.pprint :as pprint] + [clojure.string :as str] [taoensso.telemere :as t] [snippets.use-cases.view] [snippets.use-cases.delete] @@ -57,11 +58,6 @@ {:status 200 :body (snippets.use-cases.view/view-snippets-by-tag tag)})) -(defn handle-view-tags [_] - (let [tags (snippets.use-cases.view/view-tags)] - {:status 200 - :body tags})) - (defn handle-view-snippet-by-slug [{params :query-params}] (let [slug (get params "slug")] {:status 200 diff --git a/src/snippets/use_cases/view.clj b/src/snippets/use_cases/view.clj index 4edbacd..9626152 100644 --- a/src/snippets/use_cases/view.clj +++ b/src/snippets/use_cases/view.clj @@ -3,12 +3,18 @@ [taoensso.telemere :as t] [snippets.infra.db :as db])) +(defn serialize-snippet + "Converts snippet pub-date to ISO-8601 string for EDN serialization" + [snippet] + (when snippet + (assoc snippet :pub-date (.toString (:pub-date snippet))))) + (defn view-snippet [key] (t/log! {:level :info, :data {:key key}} "Viewing snippet by id") - (db/get-snippet-by-id key)) + (serialize-snippet (db/get-snippet-by-id key))) (defn view-snippets [& args] - (db/list-snippets args)) + (map serialize-snippet (db/list-snippets args))) (defn view-tags [] (t/log! {:level :info} "Viewing tags") @@ -16,8 +22,8 @@ (defn view-snippets-by-tag [tag] (t/log! {:level :info :data {:tag tag}} "Viewing snippet by tag") - (db/get-snippets-by-tag tag)) + (map serialize-snippet (db/get-snippets-by-tag tag))) (defn view-snippet-by-slug [slug] (t/log! {:level :info :data {:slug slug}} "Viewing snippet by slug") - (db/get-snippet-by-slug slug)) + (serialize-snippet (db/get-snippet-by-slug slug)))