Skip to content

Commit

Permalink
add range to snapshot list api
Browse files Browse the repository at this point in the history
  • Loading branch information
dragonpoo committed Oct 9, 2024
1 parent 911beee commit a23d600
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,19 @@
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;

import java.time.Instant;

@Repository
public interface ApplicationHistorySnapshotRepository extends ReactiveMongoRepository<ApplicationHistorySnapshot, String> {

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

Mono<Long> countByApplicationId(String applicationId);
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.lowcoder.domain.application.service;

import java.time.Instant;
import java.util.List;
import java.util.Map;

Expand All @@ -13,7 +14,7 @@ public interface ApplicationHistorySnapshotService {

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

Mono<List<ApplicationHistorySnapshot>> listAllHistorySnapshotBriefInfo(String applicationId, String compName, String theme, PageRequest pageRequest);
Mono<List<ApplicationHistorySnapshot>> listAllHistorySnapshotBriefInfo(String applicationId, String compName, String theme, Instant from, Instant to, PageRequest pageRequest);

Mono<Long> countByApplicationId(String applicationId);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ public Mono<Boolean> createHistorySnapshot(String applicationId, Map<String, Obj
}

@Override
public Mono<List<ApplicationHistorySnapshot>> listAllHistorySnapshotBriefInfo(String applicationId, String compName, String theme, PageRequest pageRequest) {
return repository.findAllByApplicationId(applicationId, compName, theme, pageRequest.withSort(Direction.DESC, "id"))
public Mono<List<ApplicationHistorySnapshot>> listAllHistorySnapshotBriefInfo(String applicationId, String compName, String theme, Instant from, Instant to, PageRequest pageRequest) {
return repository.findAllByApplicationId(applicationId, compName, theme, from, to, pageRequest.withSort(Direction.DESC, "id"))
.collectList()
.onErrorMap(Exception.class, e -> ofException(BizError.FETCH_HISTORY_SNAPSHOT_FAILURE, "FETCH_HISTORY_SNAPSHOT_FAILURE"));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,14 +55,19 @@ public Mono<ResponseView<Boolean>> create(@RequestBody ApplicationHistorySnapsho

@Override
public Mono<ResponseView<Map<String, Object>>> listAllHistorySnapshotBriefInfo(@PathVariable String applicationId,
@RequestParam(defaultValue = "0") int page, @RequestParam(defaultValue = "10") int size, @RequestParam String compName, @RequestParam String theme) {
@RequestParam(defaultValue = "0") int page,
@RequestParam(defaultValue = "10") int size,
@RequestParam String compName,
@RequestParam String theme,
@RequestParam Instant from,
@RequestParam Instant to) {

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

return sessionUserService.getVisitorId()
.delayUntil(visitor -> resourcePermissionService.checkResourcePermissionWithError(visitor, applicationId,
ResourceAction.EDIT_APPLICATIONS))
.flatMap(__ -> applicationHistorySnapshotService.listAllHistorySnapshotBriefInfo(applicationId, compName, theme, pagination.toPageRequest()))
.flatMap(__ -> applicationHistorySnapshotService.listAllHistorySnapshotBriefInfo(applicationId, compName, theme, from, to, pagination.toPageRequest()))
.flatMap(snapshotList -> {
Mono<List<ApplicationHistorySnapshotBriefInfo>> snapshotBriefInfoList = multiBuild(snapshotList,
ApplicationHistorySnapshot::getCreatedBy,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.lowcoder.api.application;

import java.time.Instant;
import java.util.Map;

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

@Operation(
tags = TAG_APPLICATION_HISTORY_MANAGEMENT,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public void testServiceMethods() {
.verifyComplete();


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

Expand All @@ -64,7 +64,7 @@ public void testServiceMethods() {
})
.verifyComplete();

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


StepVerifier.create(service.listAllHistorySnapshotBriefInfo(applicationId, null, null, PageRequest.of(0, 5))
StepVerifier.create(service.listAllHistorySnapshotBriefInfo(applicationId, null, null, null, null, PageRequest.of(0, 5))
.map(it -> it.get(0))
.map(HasIdAndAuditing::getId)
.flatMap(id -> service.getHistorySnapshotDetail(id)))
Expand Down

0 comments on commit a23d600

Please sign in to comment.