accept no limit on list-snippets
This commit is contained in:
parent
c4cc6ec2d8
commit
e5e428165f
2 changed files with 13 additions and 7 deletions
|
|
@ -32,10 +32,13 @@
|
||||||
:else {:status 500, :body "internal server error"}))))
|
:else {:status 500, :body "internal server error"}))))
|
||||||
|
|
||||||
(defn handle-view-snippets [{params :query-params}]
|
(defn handle-view-snippets [{params :query-params}]
|
||||||
(let [limit (Integer/parseInt (get params "limit" "10"))
|
(if-let [limit (get params "limit")]
|
||||||
skip (Integer/parseInt (get params "skip" "0"))]
|
(let [limit-num (Integer/parseInt limit)
|
||||||
|
skip-num (Integer/parseInt (get params "skip" "0"))]
|
||||||
{:status 200
|
{:status 200
|
||||||
:body (snippets.use-cases.view/view-snippets {:limit limit :skip skip})}))
|
:body (snippets.use-cases.view/view-snippets {:limit limit-num :skip skip-num})})
|
||||||
|
{:status 200
|
||||||
|
:body (snippets.use-cases.view/view-snippets)}))
|
||||||
|
|
||||||
(defn handle-view-snippet [{params :query-params}]
|
(defn handle-view-snippet [{params :query-params}]
|
||||||
(let [id (get params "id")]
|
(let [id (get params "id")]
|
||||||
|
|
|
||||||
|
|
@ -16,10 +16,13 @@
|
||||||
|
|
||||||
;; xtdb query docs: https://docs.xtdb.com/reference/main/xtql/queries.html#_limit
|
;; xtdb query docs: https://docs.xtdb.com/reference/main/xtql/queries.html#_limit
|
||||||
(defn list-snippets [{:keys [skip limit]}]
|
(defn list-snippets [{:keys [skip limit]}]
|
||||||
|
(if (nil? limit)
|
||||||
|
(xt/q client
|
||||||
|
'(-> (from :snippets [title pub-date tags slug markdown {:xt/id id}]) (order-by {:val pub-date, :dir :desc, :nulls :last})))
|
||||||
(xt/q client
|
(xt/q client
|
||||||
(eval
|
(eval
|
||||||
(read-string
|
(read-string
|
||||||
(format "(quote (-> (from :snippets [title pub-date tags slug markdown {:xt/id id}]) (order-by {:val pub-date, :dir :desc, :nulls :last}) (offset %s) (limit %s)))" skip limit)))))
|
(format "(quote (-> (from :snippets [title pub-date tags slug markdown {:xt/id id}]) (order-by {:val pub-date, :dir :desc, :nulls :last}) (offset %s) (limit %s)))" skip limit))))))
|
||||||
|
|
||||||
(defn get-snippet-by-id [snippet-id]
|
(defn get-snippet-by-id [snippet-id]
|
||||||
(first (xt/q client ['#(from :snippets [{:xt/id %} slug title tags {:xt/id id} markdown pub-date]) snippet-id])))
|
(first (xt/q client ['#(from :snippets [{:xt/id %} slug title tags {:xt/id id} markdown pub-date]) snippet-id])))
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue