Skip to content

Commit a71e413

Browse files
author
Thomas
committed
Reorder API
1 parent da27473 commit a71e413

File tree

7 files changed

+58
-1
lines changed

7 files changed

+58
-1
lines changed

server/api-service/lowcoder-domain/src/main/java/org/lowcoder/domain/bundle/service/BundleElementRelationService.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package org.lowcoder.domain.bundle.service;
22

33
import org.lowcoder.domain.bundle.model.BundleElement;
4+
import org.reactivestreams.Publisher;
45
import reactor.core.publisher.Flux;
56
import reactor.core.publisher.Mono;
67

@@ -14,4 +15,6 @@ public interface BundleElementRelationService {
1415
Mono<Void> create(String bundleId, String elementId);
1516

1617
Flux<BundleElement> getByElementIds(List<String> elementIds);
18+
19+
Mono<Void> updateElementPos(String bundleId, String elementId, long position);
1720
}

server/api-service/lowcoder-domain/src/main/java/org/lowcoder/domain/bundle/service/BundleElementRelationServiceImpl.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,4 +49,11 @@ public Flux<BundleElement> getByElementIds(List<String> elementIds) {
4949
return biRelationService.getByTargetIds(BUNDLE_ELEMENT, elementIds)
5050
.map(biRelation -> new BundleElement(biRelation.getSourceId(), biRelation.getTargetId(), Integer.parseInt(biRelation.getExtParam1())));
5151
}
52+
53+
@Override
54+
public Mono<Void> updateElementPos(String bundleId, String elementId, long position) {
55+
return biRelationService.getBiRelation(BUNDLE_ELEMENT, bundleId, elementId)
56+
.doOnNext(biRelation -> biRelation.setExtParam1(String.valueOf(position)))
57+
.then();
58+
}
5259
}

server/api-service/lowcoder-infra/src/main/java/org/lowcoder/infra/birelation/BiRelation.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import com.google.common.base.MoreObjects;
55
import lombok.AllArgsConstructor;
66
import lombok.NoArgsConstructor;
7+
import lombok.Setter;
78
import lombok.experimental.SuperBuilder;
89
import lombok.extern.jackson.Jacksonized;
910
import org.lowcoder.sdk.models.HasIdAndAuditing;
@@ -22,8 +23,11 @@ public class BiRelation extends HasIdAndAuditing {
2223
private String relation;
2324
private String state;
2425

26+
@Setter
2527
private String extParam1;
28+
@Setter
2629
private String extParam2;
30+
@Setter
2731
private String extParam3;
2832

2933
public BiRelationBizType getBizType() {

server/api-service/lowcoder-server/src/main/java/org/lowcoder/api/bundle/BundleApiService.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,11 @@
1111
import org.lowcoder.domain.permission.model.ResourceAction;
1212
import org.lowcoder.domain.permission.model.ResourcePermission;
1313
import org.lowcoder.domain.permission.model.ResourceRole;
14+
import org.lowcoder.sdk.config.dynamic.Conf;
1415
import reactor.core.publisher.Flux;
1516
import reactor.core.publisher.Mono;
1617

18+
import java.util.List;
1719
import java.util.Set;
1820

1921
public interface BundleApiService {
@@ -55,4 +57,6 @@ public interface BundleApiService {
5557
Mono<Boolean> setBundlePublicToMarketplace(String bundleId, BundleEndpoints.BundlePublicToMarketplaceRequest request);
5658

5759
Mono<Boolean> setBundleAsAgencyProfile(String bundleId, boolean agencyProfile);
60+
61+
Mono<Void> reorder(String bundleId, List<String> elementIds);
5862
}

server/api-service/lowcoder-server/src/main/java/org/lowcoder/api/bundle/BundleApiServiceImpl.java

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,29 @@ public Mono<Void> move(String applicationLikeId, @Nullable String targetBundleId
278278
.then();
279279
}
280280

281+
/**
282+
* Reorder the applications in bundle based on the position
283+
* @param bundleId id of the bundle to sort elements
284+
* @param elementIds ids of the elements in the bundle to sort
285+
* @return nothing
286+
*/
287+
@Override
288+
public Mono<Void> reorder(String bundleId, List<String> elementIds) {
289+
return sessionUserService.getVisitorId()
290+
// check permissions
291+
.delayUntil(userId -> resourcePermissionService.checkResourcePermissionWithError(userId, bundleId,
292+
MANAGE_BUNDLES))
293+
.flatMap(b -> Flux.fromIterable(elementIds)
294+
.index() // This will provide a tuple of (index, elementId)
295+
.flatMap(tuple -> {
296+
long index = tuple.getT1();
297+
String elementId = tuple.getT2();
298+
return bundleElementRelationService.updateElementPos(bundleId, elementId, index);
299+
})
300+
.then())
301+
.then();
302+
}
303+
281304
/**
282305
* get the sub elements of a bundle or root.
283306
*

server/api-service/lowcoder-server/src/main/java/org/lowcoder/api/bundle/BundleController.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,12 @@ public Mono<ResponseView<Void>> move(@PathVariable("id") String applicationLikeI
106106
.then(Mono.fromSupplier(() -> ResponseView.success(null)));
107107
}
108108

109+
@Override
110+
public Mono<ResponseView<Void>> reorder(@PathVariable("bundleId") String bundleId,
111+
@RequestParam(value = "elementIds", required = true) List<String> elementIds) {
112+
return bundleApiService.reorder(bundleId, elementIds)
113+
.then(Mono.fromSupplier(() -> ResponseView.success(null)));
114+
}
109115
@Override
110116
public Mono<ResponseView<Void>> updatePermission(@PathVariable String bundleId,
111117
@PathVariable String permissionId,

server/api-service/lowcoder-server/src/main/java/org/lowcoder/api/bundle/BundleEndpoints.java

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,12 +128,22 @@ public Mono<ResponseView<List<?>>> getElements(@RequestParam(value = "id", requi
128128
tags = TAG_BUNDLE_MANAGEMENT,
129129
operationId = "moveBundle",
130130
summary = "Move Bundle",
131-
description = "Relocate an Bundle Bundle to a different location in the Bundle hierarchy in Lowcoder using its unique ID."
131+
description = "Relocate an application to a different bundle in Lowcoder using its unique ID."
132132
)
133133
@PutMapping("/move/{id}")
134134
public Mono<ResponseView<Void>> move(@PathVariable("id") String applicationLikeId,
135135
@RequestParam(value = "targetBundleId", required = false) String targetBundleId);
136136

137+
@Operation(
138+
tags = TAG_BUNDLE_MANAGEMENT,
139+
operationId = "reorderBundle",
140+
summary = "Reorder Bundle",
141+
description = "Reorder bundle."
142+
)
143+
@PutMapping("/{bundleId}/reorder")
144+
public Mono<ResponseView<Void>> reorder(@PathVariable("bundleId") String bundleId,
145+
@RequestParam(value = "elementIds", required = true) List<String> elementIds);
146+
137147
@Operation(
138148
tags = TAG_BUNDLE_PERMISSIONS,
139149
operationId = "updateBundlePermissions",

0 commit comments

Comments
 (0)