Skip to content
This repository has been archived by the owner on Oct 23, 2020. It is now read-only.

Commit

Permalink
Merge pull request #216 from mehtadev17/master
Browse files Browse the repository at this point in the history
Pagination Limits
  • Loading branch information
m3brown committed Jul 29, 2014
2 parents 331d6bb + 840d53b commit 8419419
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
10 changes: 9 additions & 1 deletion src/qu/query/validation.clj
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,13 @@
(catch NumberFormatException e
(add-error query clause "Please use an integer."))))))

(defn- validate-max-offset
[query]
(let [offset (->int (:offset query) 0)]
(if (> offset 10000)
(add-error query :offset (str "The maximum offset is 10,000."))
query)))

(defn- validate-max-limit
[query max]
(let [limit (->int (:limit query) 0)]
Expand All @@ -170,5 +177,6 @@
validate-where
validate-order-by
validate-limit
validate-offset)
validate-offset
validate-max-offset)
query))
10 changes: 4 additions & 6 deletions src/qu/views.clj
Original file line number Diff line number Diff line change
Expand Up @@ -229,10 +229,11 @@
current-page (or (get-in resource [:properties :page]) 1)
href (:href resource)
limit (get-in resource [:properties :query :limit])
limit-total (if (> total 10000) 10000 total)
total-pages (if (zero? limit)
1
(+ (quot total limit)
(if (zero? (rem total limit)) 0 1)))
(+ (quot limit-total limit)
(if (zero? (rem limit-total limit)) 0 1)))
window (range (max 1 (- current-page window-size))
(inc (min total-pages (+ current-page window-size))))
in-window? (fn [page]
Expand All @@ -250,10 +251,7 @@
:href (href-for-page resource 1)})
(concat [{:page "Next"
:class (when (>= current-page total-pages) "disabled")
:href (href-for-page resource (inc current-page))}
{:page "Last"
:class (when (in-window? total-pages) "disabled")
:href (href-for-page resource total-pages)}])))
:href (when (< current-page total-pages) (href-for-page resource (inc current-page)))}])))
[]))

(defmulti slice-query (fn [format _ _] format))
Expand Down

0 comments on commit 8419419

Please sign in to comment.