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

testable filter/sorting/pagination #182

Merged
merged 2 commits into from
Apr 7, 2020
Merged

testable filter/sorting/pagination #182

merged 2 commits into from
Apr 7, 2020

Conversation

SchlottiP
Copy link
Contributor

No description provided.

@@ -63,46 +60,86 @@ func (m *MapMapper) Map(value string) (string, bool) {
return val, isValid
}

// PaginationFromRequest extracts pagination query parameter and returns a function that adds the pagination to a query
func PaginationFromRequest(r *http.Request) (QueryOption, error) {
// UrlQueryParameters contains all information that are needed for pagination, sorting and filtering.
Copy link
Contributor

Choose a reason for hiding this comment

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

either pluralize information or use "that is needed", or maybe my english is not good enough :D

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I looked it up: There is no plural of "information" :)

// even if any errors occur. The returned error combines all errors of pagination, filter and sorting.
func ReadURLQueryParameters(r *http.Request, mapper ColumnMapper, sanitizer ValueSanitizer) (*UrlQueryParameters, error) {
result := &UrlQueryParameters{}
errPagination := result.setPagination(r)
Copy link
Contributor

Choose a reason for hiding this comment

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

minor issue, setXXX implies that result does something to the pointer (method argument) it receives. This might be confusing when looking at these methods in the future.

Mabye readXXX or extractXXX?


}

func (u *UrlQueryParameters) setPagination(r *http.Request) error {
pageStr := r.URL.Query().Get("page[number]")
sizeStr := r.URL.Query().Get("page[size]")
if pageStr == "" || sizeStr == "" {
Copy link
Contributor

Choose a reason for hiding this comment

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

Can't we have a default page size? Does the jsonapi spec require both parameter to be set?

I would suggest that we allow pagination with "only" the page number.

Copy link
Contributor

Choose a reason for hiding this comment

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

e.g., we could use cfg.MinPageSize if none is set?

@SchlottiP SchlottiP merged commit 8281696 into master Apr 7, 2020
@SchlottiP SchlottiP deleted the testable_filter branch April 7, 2020 12:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants