Skip to content

Commit

Permalink
add theme 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 0181e0a commit 911beee
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,10 @@
@Repository
public interface ApplicationHistorySnapshotRepository extends ReactiveMongoRepository<ApplicationHistorySnapshot, String> {

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

Mono<Long> countByApplicationId(String applicationId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,14 @@
import org.lowcoder.domain.application.model.ApplicationHistorySnapshot;
import org.springframework.data.domain.PageRequest;

import org.springframework.web.bind.annotation.RequestParam;
import reactor.core.publisher.Mono;

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, PageRequest pageRequest);
Mono<List<ApplicationHistorySnapshot>> listAllHistorySnapshotBriefInfo(String applicationId, String compName, String theme, PageRequest pageRequest);

Mono<Long> countByApplicationId(String applicationId);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import org.springframework.data.domain.Sort.Direction;
import org.springframework.stereotype.Service;

import org.springframework.web.bind.annotation.RequestParam;
import reactor.core.publisher.Mono;

@RequiredArgsConstructor
Expand All @@ -39,15 +40,10 @@ public Mono<Boolean> createHistorySnapshot(String applicationId, Map<String, Obj
}

@Override
public Mono<List<ApplicationHistorySnapshot>> listAllHistorySnapshotBriefInfo(String applicationId, String compName, PageRequest pageRequest) {
if(compName == null || compName.isEmpty())
return repository.findAllByApplicationId(applicationId, pageRequest.withSort(Direction.DESC, "id"))
.collectList()
.onErrorMap(Exception.class, e -> ofException(BizError.FETCH_HISTORY_SNAPSHOT_FAILURE, "FETCH_HISTORY_SNAPSHOT_FAILURE"));
else
return repository.findAllByApplicationIdAndCompName(applicationId, compName, pageRequest.withSort(Direction.DESC, "id"))
.collectList()
.onErrorMap(Exception.class, e -> ofException(BizError.FETCH_HISTORY_SNAPSHOT_FAILURE, "FETCH_HISTORY_SNAPSHOT_FAILURE"));
public Mono<List<ApplicationHistorySnapshot>> listAllHistorySnapshotBriefInfo(String applicationId, String compName, String theme, PageRequest pageRequest) {
return repository.findAllByApplicationId(applicationId, compName, theme, pageRequest.withSort(Direction.DESC, "id"))
.collectList()
.onErrorMap(Exception.class, e -> ofException(BizError.FETCH_HISTORY_SNAPSHOT_FAILURE, "FETCH_HISTORY_SNAPSHOT_FAILURE"));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,14 +55,14 @@ 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(defaultValue = "0") int page, @RequestParam(defaultValue = "10") int size, @RequestParam String compName, @RequestParam String theme) {

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

return sessionUserService.getVisitorId()
.delayUntil(visitor -> resourcePermissionService.checkResourcePermissionWithError(visitor, applicationId,
ResourceAction.EDIT_APPLICATIONS))
.flatMap(__ -> applicationHistorySnapshotService.listAllHistorySnapshotBriefInfo(applicationId, compName, pagination.toPageRequest()))
.flatMap(__ -> applicationHistorySnapshotService.listAllHistorySnapshotBriefInfo(applicationId, compName, theme, pagination.toPageRequest()))
.flatMap(snapshotList -> {
Mono<List<ApplicationHistorySnapshotBriefInfo>> snapshotBriefInfoList = multiBuild(snapshotList,
ApplicationHistorySnapshot::getCreatedBy,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ 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(defaultValue = "0") int page, @RequestParam(defaultValue = "10") int size,
@RequestParam(required = false ) @Nullable String compName, @RequestParam(required = false ) @Nullable String theme);

@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, PageRequest.of(0, 5)))
StepVerifier.create(service.listAllHistorySnapshotBriefInfo(applicationId, 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, PageRequest.of(1, 1)))
StepVerifier.create(service.listAllHistorySnapshotBriefInfo(applicationId, 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, PageRequest.of(0, 5))
StepVerifier.create(service.listAllHistorySnapshotBriefInfo(applicationId, 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 911beee

Please sign in to comment.