-
Notifications
You must be signed in to change notification settings - Fork 21
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
Conversation
@@ -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. |
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.
either pluralize information or use "that is needed", or maybe my english is not good enough :D
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.
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) |
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.
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 == "" { |
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.
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.
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.
e.g., we could use cfg.MinPageSize
if none is set?
17f5f85
to
b39394c
Compare
No description provided.