Skip to content

Commit

Permalink
Bed 5258 (#1111)
Browse files Browse the repository at this point in the history
* wip: updated details endpoint to accept optional params

* readded limit check but included -1 for all responses from db

* wip:upstream client changes

* added new parse function for limit query

* ran prepare for code review
  • Loading branch information
stephanieslamb authored Jan 29, 2025
1 parent 64258e4 commit 2c8638b
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
15 changes: 15 additions & 0 deletions cmd/api/src/api/v2/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,21 @@ func ParseLimitQueryParameter(params url.Values, defaultValue int) (int, error)
}
}

// ParseOptionalLimitQueryParameter should only be used if the endpoint is safe to return all results for a given query
// This will allow the user to submit an API call with `limit=-1` which will in turn allow the database to return unlimited
// results.
func ParseOptionalLimitQueryParameter(params url.Values, defaultValue int) (int, error) {
if param := params.Get(model.PaginationQueryParameterLimit); param == "" {
return defaultValue, nil
} else if limit, err := strconv.Atoi(param); err != nil {
return 0, fmt.Errorf("error converting limit value %v to int: %v", param, err)
} else if limit < -1 {
return 0, fmt.Errorf(utils.ErrorInvalidLimit, limit)
} else {
return limit, nil
}
}

func ParseTimeQueryParameter(params url.Values, key string, defaultValue time.Time) (time.Time, error) {
if param := params.Get(key); param != "" {
return time.Parse(time.RFC3339Nano, param)
Expand Down
2 changes: 2 additions & 0 deletions packages/javascript/js-client-library/src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -539,6 +539,7 @@ class BHEAPIClient {
) => {
const params = new URLSearchParams();
params.append('finding', finding);

params.append('skip', skip.toString());
params.append('limit', limit.toString());
if (sortBy) {
Expand All @@ -556,6 +557,7 @@ class BHEAPIClient {
Object.assign(
{
params: params,
headers: options?.headers,
},
options
)
Expand Down

0 comments on commit 2c8638b

Please sign in to comment.