Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#1331: Populate folderId for app list endpoint #1380

Merged
merged 1 commit into from
Dec 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
}
}
Loading