fix view-snippets sorting

This commit is contained in:
Travis Shears 2026-03-11 09:31:15 +01:00
parent a90cabf605
commit 9146f2640d
Signed by: travisshears
GPG key ID: CB9BF1910F3F7469
2 changed files with 15 additions and 9 deletions

View file

@ -5,16 +5,20 @@ meta {
}
get {
url: {{host}}/api/snippets?limit=2&skip=0
url: {{host}}/api/snippets?limit=100&skip=0
body: none
auth: none
}
params:query {
limit: 2
limit: 100
skip: 0
}
headers {
~Accept: application/edn
}
body:json {
{
"title": "Test Snippet",

View file

@ -10,13 +10,15 @@
(assoc snippet :pub-date (.toString (:pub-date snippet)))))
(defn view-snippets [options]
(if (nil? options)
(map serialize-snippet (db/list-snippets))
(let [limit (:limit options)
skip (:skip options)]
(->> (db/list-snippets)
(sort-by :pub-date)
(reverse)
(let [limit (:limit options)
skip (:skip options)
snippets (->> (db/list-snippets)
(sort-by :pub-date)
(reverse))]
(if (nil? options)
(map serialize-snippet snippets)
(->> snippets
(drop skip)
(take limit)
(map serialize-snippet)))))