Skip to content

Commit 352e746

Browse files
dragonpooludomikula
authored andcommitted
add pagination to datasource
1 parent 82c64d7 commit 352e746

File tree

2 files changed

+24
-15
lines changed

2 files changed

+24
-15
lines changed

server/api-service/lowcoder-server/src/main/java/org/lowcoder/api/datasource/DatasourceController.java

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import org.apache.commons.collections4.CollectionUtils;
88
import org.apache.commons.lang3.BooleanUtils;
99
import org.apache.commons.lang3.StringUtils;
10+
import org.lowcoder.api.framework.view.PageResponseView;
1011
import org.lowcoder.api.framework.view.ResponseView;
1112
import org.lowcoder.api.permission.view.CommonPermissionView;
1213
import org.lowcoder.api.util.BusinessEventPublisher;
@@ -29,6 +30,7 @@
2930
import java.util.List;
3031
import java.util.Locale;
3132

33+
import static org.lowcoder.api.util.Pagination.fluxToPageResponseView;
3234
import static org.lowcoder.plugin.api.event.LowcoderEvent.EventType.*;
3335
import static org.lowcoder.sdk.exception.BizError.INVALID_PARAMETER;
3436
import static org.lowcoder.sdk.util.ExceptionUtils.ofError;
@@ -116,11 +118,11 @@ public Mono<ResponseView<DatasourceStructure>> getStructure(@PathVariable String
116118
* name, type... and the plugin definition of it, excluding the detail configs such as the connection uri, password...
117119
*/
118120
@Override
119-
public Mono<ResponseView<List<Datasource>>> listJsDatasourcePlugins(@RequestParam("appId") String applicationId, @RequestParam(required = false) String name, @RequestParam(required = false) String type) {
121+
public Mono<PageResponseView<?>> listJsDatasourcePlugins(@RequestParam("appId") String applicationId, @RequestParam(required = false) String name, @RequestParam(required = false) String type,
122+
@RequestParam(required = false, defaultValue = "0") int pageNum,
123+
@RequestParam(required = false, defaultValue = "0") int pageSize) {
120124
String objectId = gidService.convertApplicationIdToObjectId(applicationId);
121-
return datasourceApiService.listJsDatasourcePlugins(objectId, name, type)
122-
.collectList()
123-
.map(ResponseView::success);
125+
return fluxToPageResponseView(pageNum, pageSize, datasourceApiService.listJsDatasourcePlugins(objectId, name, type));
124126
}
125127

126128
/**
@@ -139,26 +141,26 @@ public Mono<ResponseView<List<Object>>> getPluginDynamicConfig(
139141

140142
@SneakyThrows
141143
@Override
142-
public Mono<ResponseView<List<DatasourceView>>> listOrgDataSources(@RequestParam(name = "orgId") String orgId, @RequestParam(required = false) String name, @RequestParam(required = false) String type) {
144+
public Mono<PageResponseView<?>> listOrgDataSources(@RequestParam(name = "orgId") String orgId, @RequestParam(required = false) String name, @RequestParam(required = false) String type,
145+
@RequestParam(required = false, defaultValue = "0") int pageNum,
146+
@RequestParam(required = false, defaultValue = "0") int pageSize) {
143147
if (StringUtils.isBlank(orgId)) {
144148
return ofError(BizError.INVALID_PARAMETER, "ORG_ID_EMPTY");
145149
}
146150
String objectId = gidService.convertOrganizationIdToObjectId(orgId);
147-
return datasourceApiService.listOrgDataSources(objectId, name, type)
148-
.collectList()
149-
.map(ResponseView::success);
151+
return fluxToPageResponseView(pageNum, pageSize, datasourceApiService.listOrgDataSources(objectId, name, type));
150152
}
151153

152154
@Override
153-
public Mono<ResponseView<List<DatasourceView>>> listAppDataSources(@RequestParam(name = "appId") String applicationId, @RequestParam(required = false) String name, @RequestParam(required = false) String type) {
155+
public Mono<PageResponseView<?>> listAppDataSources(@RequestParam(name = "appId") String applicationId, @RequestParam(required = false) String name, @RequestParam(required = false) String type,
156+
@RequestParam(required = false, defaultValue = "0") int pageNum,
157+
@RequestParam(required = false, defaultValue = "0") int pageSize) {
154158
if (StringUtils.isBlank(applicationId)) {
155159
return ofError(BizError.INVALID_PARAMETER, "INVALID_APP_ID");
156160
}
157161
String objectId = gidService.convertApplicationIdToObjectId(applicationId);
158162

159-
return datasourceApiService.listAppDataSources(objectId, name, type)
160-
.collectList()
161-
.map(ResponseView::success);
163+
return fluxToPageResponseView(pageNum, pageSize, datasourceApiService.listAppDataSources(objectId, name, type));
162164
}
163165

164166
@Override

server/api-service/lowcoder-server/src/main/java/org/lowcoder/api/datasource/DatasourceEndpoints.java

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import io.swagger.v3.oas.annotations.Operation;
55
import jakarta.annotation.Nullable;
66
import jakarta.validation.Valid;
7+
import org.lowcoder.api.framework.view.PageResponseView;
78
import org.lowcoder.api.framework.view.ResponseView;
89
import org.lowcoder.api.permission.view.CommonPermissionView;
910
import org.lowcoder.domain.datasource.model.Datasource;
@@ -99,7 +100,9 @@ public Mono<ResponseView<DatasourceStructure>> getStructure(@PathVariable String
99100
description = "Retrieve a list of node service plugins available within Lowcoder."
100101
)
101102
@GetMapping("/jsDatasourcePlugins")
102-
public Mono<ResponseView<List<Datasource>>> listJsDatasourcePlugins(@RequestParam("appId") String applicationId, @RequestParam(required = false) String name, @RequestParam(required = false) String type);
103+
public Mono<PageResponseView<?>> listJsDatasourcePlugins(@RequestParam("appId") String applicationId, @RequestParam(required = false) String name, @RequestParam(required = false) String type,
104+
@RequestParam(required = false, defaultValue = "0") int pageNum,
105+
@RequestParam(required = false, defaultValue = "0") int pageSize);
103106

104107
/**
105108
* Proxy the request to the node service, besides, add the "extra" information from the data source config stored in the mongodb if exists to
@@ -123,7 +126,9 @@ public Mono<ResponseView<List<Object>>> getPluginDynamicConfig(
123126
)
124127
@JsonView(JsonViews.Public.class)
125128
@GetMapping("/listByOrg")
126-
public Mono<ResponseView<List<DatasourceView>>> listOrgDataSources(@RequestParam(name = "orgId") String orgId, @RequestParam String name, @RequestParam String type);
129+
public Mono<PageResponseView<?>> listOrgDataSources(@RequestParam(name = "orgId") String orgId, @RequestParam String name, @RequestParam String type,
130+
@RequestParam(required = false, defaultValue = "0") int pageNum,
131+
@RequestParam(required = false, defaultValue = "0") int pageSize);
127132

128133
@Operation(
129134
tags = TAG_DATASOURCE_MANAGEMENT,
@@ -134,7 +139,9 @@ public Mono<ResponseView<List<Object>>> getPluginDynamicConfig(
134139
@Deprecated
135140
@JsonView(JsonViews.Public.class)
136141
@GetMapping("/listByApp")
137-
public Mono<ResponseView<List<DatasourceView>>> listAppDataSources(@RequestParam(name = "appId") String applicationId, @RequestParam String name, @RequestParam String type);
142+
public Mono<PageResponseView<?>> listAppDataSources(@RequestParam(name = "appId") String applicationId, @RequestParam String name, @RequestParam String type,
143+
@RequestParam(required = false, defaultValue = "0") int pageNum,
144+
@RequestParam(required = false, defaultValue = "0") int pageSize);
138145

139146
@Operation(
140147
tags = TAG_DATASOURCE_PERMISSIONS,

0 commit comments

Comments
 (0)