Skip to content

Commit 6fece96

Browse files
dragonpooludomikula
authored andcommitted
add range to snapshot list api
1 parent f1bedbf commit 6fece96

File tree

6 files changed

+27
-12
lines changed

6 files changed

+27
-12
lines changed

server/api-service/lowcoder-domain/src/main/java/org/lowcoder/domain/application/repository/ApplicationHistorySnapshotRepository.java

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,19 @@
99
import reactor.core.publisher.Flux;
1010
import reactor.core.publisher.Mono;
1111

12+
import java.time.Instant;
13+
1214
@Repository
1315
public interface ApplicationHistorySnapshotRepository extends ReactiveMongoRepository<ApplicationHistorySnapshot, String> {
1416

15-
@Query(value = "{ 'applicationId': ?0, $and: [{$or: [ { 'context.operations': { $elemMatch: { 'compName': ?1 } } }, { $expr: { $eq: [?1, null] } } ]}" +
16-
", {$or: [ { 'dsl.settings.themeId': ?2 }, { $expr: { $eq: [?2, null] } } ] } ] }",
17+
@Query(value = "{ 'applicationId': ?0, $and: [" +
18+
"{$or: [ { 'context.operations': { $elemMatch: { 'compName': ?1 } } }, { $expr: { $eq: [?1, null] } } ]}, " +
19+
"{$or: [ { 'dsl.settings.themeId': ?2 }, { $expr: { $eq: [?2, null] } } ] }, " +
20+
"{$or: [ { 'createdAt': { $gte: ?3} }, { $expr: { $eq: [?3, null] } } ] }, " +
21+
"{$or: [ { 'createdAt': { $lte: ?4} }, { $expr: { $eq: [?4, null] } } ] } " +
22+
"]}",
1723
fields = "{applicationId : 1, context: 1, createdBy : 1, createdAt : 1}")
18-
Flux<ApplicationHistorySnapshot> findAllByApplicationId(String applicationId, String compName, String theme, Pageable pageable);
24+
Flux<ApplicationHistorySnapshot> findAllByApplicationId(String applicationId, String compName, String theme, Instant createdAtFrom, Instant createdAtTo, Pageable pageable);
1925

2026
Mono<Long> countByApplicationId(String applicationId);
2127
}

server/api-service/lowcoder-domain/src/main/java/org/lowcoder/domain/application/service/ApplicationHistorySnapshotService.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package org.lowcoder.domain.application.service;
22

3+
import java.time.Instant;
34
import java.util.List;
45
import java.util.Map;
56

@@ -13,7 +14,7 @@ public interface ApplicationHistorySnapshotService {
1314

1415
Mono<Boolean> createHistorySnapshot(String applicationId, Map<String, Object> dsl, Map<String, Object> context, String userId);
1516

16-
Mono<List<ApplicationHistorySnapshot>> listAllHistorySnapshotBriefInfo(String applicationId, String compName, String theme, PageRequest pageRequest);
17+
Mono<List<ApplicationHistorySnapshot>> listAllHistorySnapshotBriefInfo(String applicationId, String compName, String theme, Instant from, Instant to, PageRequest pageRequest);
1718

1819
Mono<Long> countByApplicationId(String applicationId);
1920

server/api-service/lowcoder-domain/src/main/java/org/lowcoder/domain/application/service/impl/ApplicationHistorySnapshotServiceImpl.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@ public Mono<Boolean> createHistorySnapshot(String applicationId, Map<String, Obj
4040
}
4141

4242
@Override
43-
public Mono<List<ApplicationHistorySnapshot>> listAllHistorySnapshotBriefInfo(String applicationId, String compName, String theme, PageRequest pageRequest) {
44-
return repository.findAllByApplicationId(applicationId, compName, theme, pageRequest.withSort(Direction.DESC, "id"))
43+
public Mono<List<ApplicationHistorySnapshot>> listAllHistorySnapshotBriefInfo(String applicationId, String compName, String theme, Instant from, Instant to, PageRequest pageRequest) {
44+
return repository.findAllByApplicationId(applicationId, compName, theme, from, to, pageRequest.withSort(Direction.DESC, "id"))
4545
.collectList()
4646
.onErrorMap(Exception.class, e -> ofException(BizError.FETCH_HISTORY_SNAPSHOT_FAILURE, "FETCH_HISTORY_SNAPSHOT_FAILURE"));
4747
}

server/api-service/lowcoder-server/src/main/java/org/lowcoder/api/application/ApplicationHistorySnapshotController.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,14 +55,19 @@ public Mono<ResponseView<Boolean>> create(@RequestBody ApplicationHistorySnapsho
5555

5656
@Override
5757
public Mono<ResponseView<Map<String, Object>>> listAllHistorySnapshotBriefInfo(@PathVariable String applicationId,
58-
@RequestParam(defaultValue = "0") int page, @RequestParam(defaultValue = "10") int size, @RequestParam String compName, @RequestParam String theme) {
58+
@RequestParam(defaultValue = "0") int page,
59+
@RequestParam(defaultValue = "10") int size,
60+
@RequestParam String compName,
61+
@RequestParam String theme,
62+
@RequestParam Instant from,
63+
@RequestParam Instant to) {
5964

6065
Pagination pagination = Pagination.of(page, size).check();
6166

6267
return sessionUserService.getVisitorId()
6368
.delayUntil(visitor -> resourcePermissionService.checkResourcePermissionWithError(visitor, applicationId,
6469
ResourceAction.EDIT_APPLICATIONS))
65-
.flatMap(__ -> applicationHistorySnapshotService.listAllHistorySnapshotBriefInfo(applicationId, compName, theme, pagination.toPageRequest()))
70+
.flatMap(__ -> applicationHistorySnapshotService.listAllHistorySnapshotBriefInfo(applicationId, compName, theme, from, to, pagination.toPageRequest()))
6671
.flatMap(snapshotList -> {
6772
Mono<List<ApplicationHistorySnapshotBriefInfo>> snapshotBriefInfoList = multiBuild(snapshotList,
6873
ApplicationHistorySnapshot::getCreatedBy,

server/api-service/lowcoder-server/src/main/java/org/lowcoder/api/application/ApplicationHistorySnapshotEndpoints.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package org.lowcoder.api.application;
22

3+
import java.time.Instant;
34
import java.util.Map;
45

56
import jakarta.annotation.Nullable;
@@ -41,7 +42,9 @@ public interface ApplicationHistorySnapshotEndpoints
4142
@GetMapping("/{applicationId}")
4243
public Mono<ResponseView<Map<String, Object>>> listAllHistorySnapshotBriefInfo(@PathVariable String applicationId,
4344
@RequestParam(defaultValue = "0") int page, @RequestParam(defaultValue = "10") int size,
44-
@RequestParam(required = false ) @Nullable String compName, @RequestParam(required = false ) @Nullable String theme);
45+
@RequestParam(required = false ) @Nullable String compName, @RequestParam(required = false ) @Nullable String theme,
46+
@RequestParam(required = false ) @Nullable Instant from,
47+
@RequestParam(required = false ) @Nullable Instant to);
4548

4649
@Operation(
4750
tags = TAG_APPLICATION_HISTORY_MANAGEMENT,

server/api-service/lowcoder-server/src/test/java/org/lowcoder/api/service/impl/ApplicationHistorySnapshotServiceTest.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public void testServiceMethods() {
4444
.verifyComplete();
4545

4646

47-
StepVerifier.create(service.listAllHistorySnapshotBriefInfo(applicationId, null, null, PageRequest.of(0, 5)))
47+
StepVerifier.create(service.listAllHistorySnapshotBriefInfo(applicationId, null, null, null, null, PageRequest.of(0, 5)))
4848
.assertNext(list -> {
4949
assertEquals(2, list.size());
5050

@@ -64,7 +64,7 @@ public void testServiceMethods() {
6464
})
6565
.verifyComplete();
6666

67-
StepVerifier.create(service.listAllHistorySnapshotBriefInfo(applicationId, null, null, PageRequest.of(1, 1)))
67+
StepVerifier.create(service.listAllHistorySnapshotBriefInfo(applicationId, null, null, null, null, PageRequest.of(1, 1)))
6868
.assertNext(list -> {
6969
assertEquals(1, list.size());
7070
ApplicationHistorySnapshot one = list.get(0);
@@ -75,7 +75,7 @@ public void testServiceMethods() {
7575
.verifyComplete();
7676

7777

78-
StepVerifier.create(service.listAllHistorySnapshotBriefInfo(applicationId, null, null, PageRequest.of(0, 5))
78+
StepVerifier.create(service.listAllHistorySnapshotBriefInfo(applicationId, null, null, null, null, PageRequest.of(0, 5))
7979
.map(it -> it.get(0))
8080
.map(HasIdAndAuditing::getId)
8181
.flatMap(id -> service.getHistorySnapshotDetail(id)))

0 commit comments

Comments
 (0)