Skip to content

Commit

Permalink
#1331: Populate folderId for app list endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
dragonpoo committed Dec 5, 2024
1 parent 18e2917 commit 318d736
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 17 deletions.
Original file line number Diff line number Diff line change
@@ -1,22 +1,10 @@
package org.lowcoder.api.application;

import static org.apache.commons.collections4.SetUtils.emptyIfNull;
import static org.lowcoder.plugin.api.event.LowcoderEvent.EventType.APPLICATION_CREATE;
import static org.lowcoder.plugin.api.event.LowcoderEvent.EventType.APPLICATION_DELETE;
import static org.lowcoder.plugin.api.event.LowcoderEvent.EventType.APPLICATION_RECYCLED;
import static org.lowcoder.plugin.api.event.LowcoderEvent.EventType.APPLICATION_RESTORE;
import static org.lowcoder.plugin.api.event.LowcoderEvent.EventType.APPLICATION_UPDATE;
import static org.lowcoder.plugin.api.event.LowcoderEvent.EventType.APPLICATION_VIEW;
import static org.lowcoder.sdk.exception.BizError.INVALID_PARAMETER;
import static org.lowcoder.sdk.util.ExceptionUtils.ofError;

import java.util.List;

import lombok.RequiredArgsConstructor;
import org.lowcoder.api.application.view.ApplicationInfoView;
import org.lowcoder.api.application.view.ApplicationPermissionView;
import org.lowcoder.api.application.view.ApplicationView;
import org.lowcoder.api.application.view.MarketplaceApplicationInfoView;
// should we not have a AgencyApplicationInfoView
import org.lowcoder.api.framework.view.PageResponseView;
import org.lowcoder.api.framework.view.ResponseView;
import org.lowcoder.api.home.SessionUserService;
Expand All @@ -28,15 +16,21 @@
import org.lowcoder.domain.application.model.ApplicationRequestType;
import org.lowcoder.domain.application.model.ApplicationStatus;
import org.lowcoder.domain.application.model.ApplicationType;
import org.lowcoder.domain.folder.service.FolderElementRelationService;
import org.lowcoder.domain.permission.model.ResourceRole;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import lombok.RequiredArgsConstructor;
import reactor.core.publisher.Mono;

import java.util.List;

import static org.apache.commons.collections4.SetUtils.emptyIfNull;
import static org.lowcoder.plugin.api.event.LowcoderEvent.EventType.*;
import static org.lowcoder.sdk.exception.BizError.INVALID_PARAMETER;
import static org.lowcoder.sdk.util.ExceptionUtils.ofError;

@RequiredArgsConstructor
@RestController
public class ApplicationController implements ApplicationEndpoints {
Expand All @@ -46,6 +40,7 @@ public class ApplicationController implements ApplicationEndpoints {
private final BusinessEventPublisher businessEventPublisher;
private final SessionUserService sessionUserService;
private final GidService gidService;
private final FolderElementRelationService folderElementRelationService;

@Override
public Mono<ResponseView<ApplicationView>> create(@RequestBody CreateApplicationRequest createApplicationRequest) {
Expand Down Expand Up @@ -166,7 +161,15 @@ public Mono<ResponseView<List<ApplicationInfoView>>> getApplications(@RequestPar
@RequestParam(required = false, defaultValue = "1") Integer pageNum,
@RequestParam(required = false, defaultValue = "0") Integer pageSize) {
ApplicationType applicationTypeEnum = applicationType == null ? null : ApplicationType.fromValue(applicationType);
var flux = userHomeApiService.getAllAuthorisedApplications4CurrentOrgMember(applicationTypeEnum, applicationStatus, withContainerSize, name, category).cache();
var flux = userHomeApiService.getAllAuthorisedApplications4CurrentOrgMember(applicationTypeEnum, applicationStatus, withContainerSize, name, category)
.delayUntil(applicationInfoView -> {
String applicationId = applicationInfoView.getApplicationId();
return folderElementRelationService.getByElementIds(List.of(applicationId))
.doOnNext(folderElement -> {
applicationInfoView.setFolderId(folderElement.folderId());
}).then();
})
.cache();
Mono<Long> countMono = flux.count();
var flux1 = flux.skip((long) (pageNum - 1) * pageSize);
if(pageSize > 0) flux1 = flux1.take(pageSize);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public class ApplicationInfoView {
@JsonInclude(Include.NON_NULL)
private final Object containerSize; // for module size
@Nullable
private final String folderId;
private String folderId;

@Nullable
private final Instant lastViewTime; // user last visit time for this app
Expand Down Expand Up @@ -61,4 +61,7 @@ public long getLastEditedAt() {
public boolean isFolder() {
return false;
}
public void setFolderId(@Nullable String folderId) {
this.folderId = folderId;
}
}

0 comments on commit 318d736

Please sign in to comment.