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 { get {
url: {{host}}/api/snippets?limit=2&skip=0 url: {{host}}/api/snippets?limit=100&skip=0
body: none body: none
auth: none auth: none
} }
params:query { params:query {
limit: 2 limit: 100
skip: 0 skip: 0
} }
headers {
~Accept: application/edn
}
body:json { body:json {
{ {
"title": "Test Snippet", "title": "Test Snippet",

View file

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