Repository navigation
Add optional paging in M1-M3 BE APIs (where applicable), add missing endpoint and add get token local util script #5207
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
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| // Copyright The Linux Foundation and each contributor to CommunityBridge. | ||
| // SPDX-License-Identifier: MIT | ||
|
|
||
| package utils | ||
|
|
||
| // PageBounds converts the optional pageSize/offset query parameters into | ||
| // [start, end) slice bounds for an in-memory list of totalCount entries. | ||
| // When both parameters are nil the full range is returned, keeping the | ||
| // non-paged behavior unchanged. | ||
| func PageBounds(totalCount int, pageSize, offset *int64) (int, int) { | ||
| start, end := 0, totalCount | ||
| if offset != nil && *offset > 0 { | ||
| if *offset >= int64(totalCount) { | ||
| start = totalCount | ||
| } else { | ||
| start = int(*offset) | ||
| } | ||
| } | ||
| if pageSize != nil && *pageSize > 0 && int64(end-start) > *pageSize { | ||
| end = start + int(*pageSize) | ||
| } | ||
| return start, end | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| // Copyright The Linux Foundation and each contributor to CommunityBridge. | ||
| // SPDX-License-Identifier: MIT | ||
|
|
||
| package utils | ||
|
|
||
| import ( | ||
| "testing" | ||
|
|
||
| "github.com/aws/aws-sdk-go/aws" | ||
| "github.com/stretchr/testify/assert" | ||
| ) | ||
|
|
||
| func TestPageBounds(t *testing.T) { | ||
| cases := []struct { | ||
| name string | ||
| total int | ||
| pageSize *int64 | ||
| offset *int64 | ||
| wantStart int | ||
| wantEnd int | ||
| }{ | ||
| {"no paging", 10, nil, nil, 0, 10}, | ||
| {"page size only", 10, aws.Int64(3), nil, 0, 3}, | ||
| {"offset only", 10, nil, aws.Int64(4), 4, 10}, | ||
| {"page size and offset", 10, aws.Int64(3), aws.Int64(4), 4, 7}, | ||
| {"last partial page", 10, aws.Int64(3), aws.Int64(9), 9, 10}, | ||
| {"offset at end", 10, aws.Int64(3), aws.Int64(10), 10, 10}, | ||
| {"offset beyond end", 10, aws.Int64(3), aws.Int64(42), 10, 10}, | ||
| {"page size beyond end", 10, aws.Int64(100), nil, 0, 10}, | ||
| {"zero page size ignored", 10, aws.Int64(0), nil, 0, 10}, | ||
| {"zero offset ignored", 10, nil, aws.Int64(0), 0, 10}, | ||
| {"empty list", 0, aws.Int64(5), aws.Int64(2), 0, 0}, | ||
| } | ||
| for _, tc := range cases { | ||
| t.Run(tc.name, func(t *testing.T) { | ||
| start, end := PageBounds(tc.total, tc.pageSize, tc.offset) | ||
| assert.Equal(t, tc.wantStart, start, "start") | ||
| assert.Equal(t, tc.wantEnd, end, "end") | ||
| }) | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.