Skip to content

Commit

Permalink
[Blazebit#795] fix offset parameter in spring data rest integration
Browse files Browse the repository at this point in the history
  • Loading branch information
Mobe91 committed May 9, 2019
1 parent 7e8277c commit cb2bbb0
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
public class KeysetPageRequest extends PageRequest implements KeysetPageable {

private final KeysetPage keysetPage;
private final int offset;
private final long offset;

/**
* Construct a page request with an optional keyset page that may be used for keyset pagination.
Expand Down Expand Up @@ -79,17 +79,22 @@ public KeysetPageRequest(KeysetPage keysetPage, Sort sort) {
* @param pageSize The number of elements per page
* @since 1.3.0
*/
public KeysetPageRequest(KeysetPage keysetPage, Sort sort, int offset, int pageSize) {
super(offset / pageSize, pageSize, sort);
public KeysetPageRequest(KeysetPage keysetPage, Sort sort, long offset, int pageSize) {
super((int) (offset / pageSize), pageSize, sort);
this.keysetPage = keysetPage;
this.offset = offset;
}

@Override
public int getIntOffset() {
public long getOffset() {
return offset;
}

@Override
public int getIntOffset() {
return (int) offset;
}

@Override
public KeysetPage getKeysetPage() {
return keysetPage;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ public KeysetPageable resolveArgument(MethodParameter methodParameter, ModelAndV

int offset;
if (StringUtils.hasText(offsetString)) {
offset = parseAndApplyBoundaries(pageString, Integer.MAX_VALUE, false);
offset = parseAndApplyBoundaries(offsetString, Integer.MAX_VALUE, false);
} else if (StringUtils.hasText(pageString)) {
offset = pageSize * parseAndApplyBoundaries(pageString, Integer.MAX_VALUE, true);
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,19 @@ public void testDocumentControllerDefaults() throws Exception {
.andExpect(jsonPath("$.keysetPage.highest.tuple[0]", is(d2.getId().intValue())));
}

@Test
public void testDocumentControllerOffsetParameter() throws Exception {
// Given
createDocument("D1");
Document d2 = createDocument("D2");

// When / Then
mockMvc.perform(get("/document-views?offset={offset}&size={size}", 1, 2))
.andExpect(status().isOk())
.andExpect(jsonPath("$.numberOfElements", is(1)))
.andExpect(jsonPath("$.content[0].id", is(d2.getId().intValue())));
}

private Document createDocument(String name) {
return createDocument(name, null);
}
Expand Down

0 comments on commit cb2bbb0

Please sign in to comment.