add serialize logic in view use-case
This commit is contained in:
parent
3b202740e9
commit
c4cc6ec2d8
2 changed files with 11 additions and 9 deletions
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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)))
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue