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 a Sort RequestOption helper #298

Merged
merged 2 commits into from
Oct 25, 2023
Merged

Add a Sort RequestOption helper #298

merged 2 commits into from
Oct 25, 2023

Conversation

ewanharris
Copy link
Contributor

🔧 Changes

Adds a Sort helper function that can be used to configure the field to sort by and direction.

Closes #221

📚 References

🔬 Testing

📝 Checklist

  • All new/changed/fixed functionality is covered by tests (or N/A)
  • I have added documentation for all new/changed functionality (or N/A)

@ewanharris ewanharris requested a review from a team as a code owner October 24, 2023 11:13
@codecov-commenter
Copy link

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (1f406ac) 94.80% compared to head (a47d2d0) 94.80%.

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #298   +/-   ##
=======================================
  Coverage   94.80%   94.80%           
=======================================
  Files          46       46           
  Lines        8910     8916    +6     
=======================================
+ Hits         8447     8453    +6     
  Misses        361      361           
  Partials      102      102           
Files Coverage Δ
management/management_request.go 83.33% <100.00%> (+0.64%) ⬆️

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.


// Sort configures a request to sort data by the selected field.
// Use 1 to sort ascending and -1 to sort descending.
func Sort(sort string) RequestOption {
Copy link
Contributor

@Widcket Widcket Oct 24, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we use a string parameter for the field, and a boolean for the sort direction? Instead of expecting the exact string that the underlying API endpoint expects.

Copy link
Contributor Author

@ewanharris ewanharris Oct 24, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd noodled around with this a bit, initially I had Sort("name", "-1") then I looked at Java/.Net and they had a style like what I went with (Sort("name:-1")) but I'm on the fence about it as they all kinda hide what the real meaning of 1/-1 are so on a scan through usage it's not immediately obvious what's being performed.

I did consider doing SortAscending("name") and SortDescending("name") to make it clearer but figured two might be overkill, what do you think?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agree that "1" and "-1" don't really express much about what they mean.

I did consider doing SortAscending("name") and SortDescending("name") to make it clearer

How are we already handling similar cases in the public API, if any?
BTW these seem quite readable to me.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There isn't really anything too like this unfortunately, I guess the closest might the the Query API allowing passing similar strings

@ewanharris ewanharris merged commit e979f85 into main Oct 25, 2023
4 checks passed
@ewanharris ewanharris deleted the feat/sort-helper branch October 25, 2023 08:39
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.

Sorting
3 participants