-
Notifications
You must be signed in to change notification settings - Fork 547
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add standardized models for cursor based pagination (#949)
Co-authored-by: Karthik Ramgopal <[email protected]>
- Loading branch information
1 parent
76980d0
commit 668bff9
Showing
5 changed files
with
54 additions
and
2 deletions.
There are no files selected for viewing
This file contains 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 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
13 changes: 13 additions & 0 deletions
13
restli-common/src/main/pegasus/com/linkedin/restli/common/CursorPagination.pdl
This file contains 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,13 @@ | ||
namespace com.linkedin.restli.common | ||
|
||
/** | ||
* Metadata for cursor based pagination with collections. | ||
*/ | ||
record CursorPagination { | ||
|
||
/** | ||
* Pagination cursor that points to the end of the current page and can be used to fetch the next page. | ||
* Not populated if the current page is the last page. | ||
*/ | ||
next: optional string | ||
} |
12 changes: 12 additions & 0 deletions
12
.../src/main/resources/legacyPegasusSchemas/com/linkedin/restli/common/CursorPagination.pdsc
This file contains 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,12 @@ | ||
{ | ||
"type" : "record", | ||
"name" : "CursorPagination", | ||
"namespace" : "com.linkedin.restli.common", | ||
"doc" : "Metadata for cursor based pagination with collections.", | ||
"fields" : [ { | ||
"name" : "next", | ||
"type" : "string", | ||
"doc" : "Pagination cursor that points to the end of the current page and can be used to fetch the next page.\nNot populated if the current page is the last page.", | ||
"optional" : true | ||
} ] | ||
} |
23 changes: 23 additions & 0 deletions
23
restli-server/src/main/java/com/linkedin/restli/server/CursorCollectionResult.java
This file contains 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 @@ | ||
package com.linkedin.restli.server; | ||
|
||
import com.linkedin.data.template.RecordTemplate; | ||
import com.linkedin.restli.common.CursorPagination; | ||
import java.util.List; | ||
|
||
|
||
/** | ||
* Convenience extension to {@link CollectionResult} for use with cursor based pagination. | ||
*/ | ||
public class CursorCollectionResult<T extends RecordTemplate> extends CollectionResult<T, CursorPagination> | ||
{ | ||
/** | ||
* Constructor | ||
* | ||
* @param elements List of elements in the current page. | ||
* @param pagination The cursor pagination metadata. | ||
*/ | ||
public CursorCollectionResult(final List<T> elements, CursorPagination pagination) | ||
{ | ||
super(elements, null, pagination); | ||
} | ||
} |