From c98612571c5ef1d33e13e8bae7859cd8765744e2 Mon Sep 17 00:00:00 2001 From: ReyhanPatria <62297881+ReyhanPatria@users.noreply.github.com> Date: Thu, 4 Nov 2021 10:11:03 +0700 Subject: [PATCH] Added cursor pagination (#1056) --- .../catalog/resources/bots/BotsResource.java | 28 +++++++++++++++++-- 1 file changed, 25 insertions(+), 3 deletions(-) diff --git a/catalog-rest-service/src/main/java/org/openmetadata/catalog/resources/bots/BotsResource.java b/catalog-rest-service/src/main/java/org/openmetadata/catalog/resources/bots/BotsResource.java index a33e0ed7b31..dc533aaa8e8 100644 --- a/catalog-rest-service/src/main/java/org/openmetadata/catalog/resources/bots/BotsResource.java +++ b/catalog-rest-service/src/main/java/org/openmetadata/catalog/resources/bots/BotsResource.java @@ -20,6 +20,7 @@ import com.fasterxml.jackson.core.JsonProcessingException; import com.google.inject.Inject; import io.swagger.annotations.Api; import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.Parameter; import io.swagger.v3.oas.annotations.media.Content; import io.swagger.v3.oas.annotations.media.Schema; import io.swagger.v3.oas.annotations.responses.ApiResponse; @@ -33,7 +34,10 @@ import org.openmetadata.catalog.util.EntityUtil.Fields; import org.openmetadata.catalog.util.RestUtil; import org.openmetadata.catalog.util.ResultList; +import javax.validation.constraints.Max; +import javax.validation.constraints.Min; import javax.ws.rs.Consumes; +import javax.ws.rs.DefaultValue; import javax.ws.rs.GET; import javax.ws.rs.POST; import javax.ws.rs.Path; @@ -90,10 +94,28 @@ public class BotsResource { BotsList.class))) }) public ResultList list(@Context UriInfo uriInfo, - @Context SecurityContext securityContext, - @QueryParam("name") String name) throws IOException, GeneralSecurityException, ParseException { - ResultList list = dao.listAfter(null, name, 10000, null); + @Context SecurityContext securityContext, + @QueryParam("name") String name, + @DefaultValue("10") + @Min(1) + @Max(1000000) + @QueryParam("limit") int limitParam, + @Parameter(description = "Returns list of tables before this cursor", + schema = @Schema(type = "string")) + @QueryParam("before") String before, + @Parameter(description = "Returns list of tables after this cursor", + schema = @Schema(type = "string")) + @QueryParam("after") String after) throws IOException, GeneralSecurityException, ParseException { + RestUtil.validateCursors(before, after); + + ResultList list; + if (before != null) { // Reverse paging + list = dao.listBefore(null, name, limitParam, before); + } else { // Forward paging or first page + list = dao.listAfter(null, name, limitParam, after); + } list.getData().forEach(b -> addHref(uriInfo, b)); + return list; }