-
-
Notifications
You must be signed in to change notification settings - Fork 115
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add hasNext
and hasPrevious
properties
#482
base: main
Are you sure you want to change the base?
Conversation
These properties are similar to the flask-sqlalchemy properties `has_next` and `has_prev`.
Can you add some tests to this? Especially to check the boundaries/edge cases. Like count of 0, trying to pass in a page of -1 etc |
let remainingItems = total - (per * page) | ||
if remainingItems <= 0 { | ||
self.hasNext = false | ||
} else { | ||
self.hasNext = true | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How do we feel about one-liners like below?
let remainingItems = total - (per * page) | |
if remainingItems <= 0 { | |
self.hasNext = false | |
} else { | |
self.hasNext = true | |
} | |
self.hasNext = (total - (per * page)) <= 0 | |
self.hasPrevious = page > 1 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Personally I'd choose the existing code, it's a bit easier to read at a glance. But I don't have a strong opinion on it
Should I add bounds to |
Yes we definitely need tests and count checking for this |
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #482 +/- ##
==========================================
+ Coverage 47.39% 47.52% +0.13%
==========================================
Files 106 106
Lines 4756 4768 +12
==========================================
+ Hits 2254 2266 +12
Misses 2502 2502
|
This PR adds the properties
hasNext
andhasPrevious
which are similar to the flask-sqlalchemy propertieshas_next
andhas_prev
.