Skip to content
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

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

noahpistilli
Copy link

This PR adds the properties hasNext and hasPrevious which are similar to the flask-sqlalchemy properties has_next and has_prev.

These properties are similar to the flask-sqlalchemy properties `has_next` and `has_prev`.
@0xTim
Copy link
Member

0xTim commented Feb 17, 2022

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

Comment on lines +91 to +96
let remainingItems = total - (per * page)
if remainingItems <= 0 {
self.hasNext = false
} else {
self.hasNext = true
}

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?

Suggested change
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

Copy link
Member

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

@noahpistilli
Copy link
Author

noahpistilli commented Feb 20, 2024

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

Should I add bounds to PageMetadata.page and PageMetadata.per then? Right now it will gladly accept a negative page number and a value of 0

@0xTim
Copy link
Member

0xTim commented Feb 20, 2024

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

Should I add bounds to PageMetadata.page and PageMetadata.per then? Right now it will gladly accept a negative page number and a value of 0

Yes we definitely need tests and count checking for this

@codecov-commenter
Copy link

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (bb47433) 47.39% compared to head (affcd01) 47.52%.

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              
Files Coverage Δ
...luentKit/Query/Builder/QueryBuilder+Paginate.swift 80.00% <100.00%> (+5.00%) ⬆️

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants