add isFavorite to project list api (#26)

* feat: add isFavorite to project list api

* feat:update frontend resources
This commit is contained in:
vran
2022-02-25 20:55:00 +08:00
committed by GitHub
parent decd76dd42
commit e799940c2d
29 changed files with 49 additions and 23 deletions

View File

@@ -33,5 +33,6 @@ public interface ProjectResponseConverter {
@Mapping(target = "createAt", source = "project.createAt")
ProjectSimpleResponse toSimple(ProjectPojo project,
DataSourcePojo dataSource,
ProjectSyncRulePojo syncRule);
ProjectSyncRulePojo syncRule,
Boolean isFavorite);
}

View File

@@ -19,6 +19,8 @@ public class ProjectSimpleResponse {
private Boolean isAutoSync;
private Boolean isFavorite;
private String autoSyncCron;
private LocalDateTime createAt;

View File

@@ -17,10 +17,7 @@ import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.StringUtils;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.Properties;
import java.util.*;
import java.util.function.Function;
import java.util.stream.Collectors;
@@ -38,6 +35,8 @@ public class ProjectService {
private final DataSourcePropertyDao dataSourcePropertyDao;
private final UserFavoriteProjectDao userFavoriteProjectDao;
private final DataSourcePojoConverter dataSourcePojoConverter;
private final ProjectPojoConverter projectPojoConverter;
@@ -128,7 +127,7 @@ public class ProjectService {
projectSyncRuleDao.disableAutoSyncByProjectId(projectId);
}
public Page<ProjectSimpleResponse> list(Pageable page, ProjectListCondition condition) {
public Page<ProjectSimpleResponse> list(Integer userId, Pageable page, ProjectListCondition condition) {
Page<ProjectPojo> pageData = projectDao.selectByCondition(page, condition.toCondition());
List<Integer> projectIds = pageData.getContent()
.stream()
@@ -140,10 +139,15 @@ public class ProjectService {
Map<Integer, ProjectSyncRulePojo> syncRuleMapByProjectId = projectSyncRuleDao.selectInProjectIds(projectIds)
.stream()
.collect(Collectors.toMap(ProjectSyncRulePojo::getProjectId, Function.identity()));
Set<Integer> favoriteProjectIds = userFavoriteProjectDao.selectByUserIdAndProjectIds(userId, projectIds)
.stream()
.map(UserFavoriteProjectPojo::getProjectId)
.collect(Collectors.toSet());
return pageData.map(project -> {
DataSourcePojo dataSource = dataSourceMapByProjectId.get(project.getId());
ProjectSyncRulePojo syncRule = syncRuleMapByProjectId.get(project.getId());
return projectResponseConverter.toSimple(project, dataSource, syncRule);
Boolean isFavorite = favoriteProjectIds.contains(project.getId());
return projectResponseConverter.toSimple(project, dataSource, syncRule, isFavorite);
});
}