Files
onspring-api-sdk-go/apps.go
T
Stevan Freeborn 126b027a81 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.
2026-01-15 17:03:59 -06:00

48 lines
794 B
Go

package onspring
import (
"context"
"net/http"
)
const (
appsPath = "/apps"
)
type AppsEndpoint struct {
client *Client
}
type App struct {
Href string `json:"href"`
Id int `json:"id"`
Name string `json:"name"`
}
func (p *AppsEndpoint) Get(ctx context.Context, pagingOpts ...PagingOption) (Page[App], error) {
pagingRequest := &PagingRequest{
pageNumber: 1,
pageSize: 50,
}
for _, opt := range pagingOpts {
opt(pagingRequest)
}
req, requestCreationErr := p.client.newRequest(ctx, http.MethodGet, appsPath, pagingRequest.ToParams(), nil)
var page Page[App]
if requestCreationErr != nil {
return page, requestCreationErr
}
responseErr := p.client.doWithJsonResponse(req, &page)
if responseErr != nil {
return page, responseErr
}
return page, nil
}