fix: correct paging parameter logic and add paging options
- fix bug where `pageNumber` and `pageSize` were swapped during default initialization in `apps.go`. - fix bug in `pagingRequest.go` where `ToParams` mapped keys to the incorrect struct fields. - add `ForPageNumber` and `WithPageSize` functional options to allow custom paging configuration. - enhance `Apps` endpoint tests to verify that `pageNumber` and `pageSize` query parameters are correctly passed to the API. - add test case for verifying non-default paging options.
This commit is contained in:
+15
-3
@@ -3,15 +3,27 @@ package onspring
|
||||
import "strconv"
|
||||
|
||||
type PagingRequest struct {
|
||||
pageSize int
|
||||
pageNumber int
|
||||
pageSize int
|
||||
}
|
||||
|
||||
func (pr *PagingRequest) ToParams() map[string]string {
|
||||
return map[string]string{
|
||||
"pageSize": strconv.Itoa(pr.pageNumber),
|
||||
"pageNumber": strconv.Itoa(pr.pageSize),
|
||||
"pageNumber": strconv.Itoa(pr.pageNumber),
|
||||
"pageSize": strconv.Itoa(pr.pageSize),
|
||||
}
|
||||
}
|
||||
|
||||
type PagingOption func(*PagingRequest)
|
||||
|
||||
func ForPageNumber(pageNumber int) PagingOption {
|
||||
return func(pr *PagingRequest) {
|
||||
pr.pageNumber = pageNumber
|
||||
}
|
||||
}
|
||||
|
||||
func WithPageSize(pageSize int) PagingOption {
|
||||
return func(pr *PagingRequest) {
|
||||
pr.pageSize = pageSize
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user