Skip to content

Commit

Permalink
Merge pull request #87 from 9oormthon-univ/86-fix-인사이트-정보-반환-시-폴더-색상-…
Browse files Browse the repository at this point in the history
…같이-반환하기

fix: 인사이트 정보 반환 시 폴더 색상 같이 반환하기
  • Loading branch information
MinhoJJang authored Jul 5, 2024
2 parents 299be76 + 6813011 commit 02abb61
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 23 deletions.
26 changes: 16 additions & 10 deletions src/main/java/goorm/reinput/folder/service/FolderService.java
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,6 @@ public FolderShareResponseDto createShareLink(Long userId, FolderShareDto folder
.build();
}


public List<InsightSimpleResponseDto> findAllInsights(Long userId, String keyword) {
log.info("[FolderService] findAllInsights {} called", userId);
// todo : searchInsights 쿼리 최적화 버전 테스트후 적용
Expand All @@ -206,15 +205,22 @@ public List<InsightSimpleResponseDto> findAllInsights(Long userId, String keywor
.sorted(Comparator.comparing(InsightSearchDto::getMatchScore).reversed())
.toList();


return sortedInsightSearchDtos.stream().map(insightSearchDto -> InsightSimpleResponseDto.builder()
.insightId(insightSearchDto.getInsightId())
.insightMainImage(insightSearchDto.getInsightMainImage())
.insightTitle(insightSearchDto.getInsightTitle())
.insightSummary(insightSearchDto.getInsightSummary())
.insightTagList(insightSearchDto.getInsightTagList())
.build())
return sortedInsightSearchDtos.stream()
.map(insightSearchDto -> {
// Insight 엔티티를 조회하여 folderColor를 가져옴
Insight insight = insightRepository.findByInsightId(insightSearchDto.getInsightId())
.orElseThrow(() -> new IllegalArgumentException("Insight not found with id: " + insightSearchDto.getInsightId()));
FolderColor folderColor = insight.getFolder().getFolderColor();

return InsightSimpleResponseDto.builder()
.insightId(insightSearchDto.getInsightId())
.insightMainImage(insightSearchDto.getInsightMainImage())
.insightTitle(insightSearchDto.getInsightTitle())
.insightSummary(insightSearchDto.getInsightSummary())
.insightTagList(insightSearchDto.getInsightTagList())
.folderColor(folderColor)
.build();
})
.collect(Collectors.toList());
}

}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package goorm.reinput.insight.domain.dto;

import goorm.reinput.folder.domain.FolderColor;
import goorm.reinput.reminder.domain.RemindType;
import goorm.reinput.reminder.domain.ReminderQuestion;
import lombok.*;
Expand Down Expand Up @@ -28,6 +29,7 @@ public class InsightResponseDto {
private List<Integer> remindDays;
private String folderName;
private Long folderId;
private FolderColor folderColor;

// 소유자가 볼 경우 리마인더 질문이 보임
private List<ReminderQuestion> reminderQuestionList;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package goorm.reinput.insight.domain.dto;

import goorm.reinput.folder.domain.FolderColor;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
Expand All @@ -26,6 +27,7 @@ public class InsightShareResponseDto {

private String folderName;
private Long folderId;
private FolderColor folderColor;

private Boolean isCopyable;
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package goorm.reinput.insight.domain.dto;

import goorm.reinput.folder.domain.FolderColor;
import lombok.*;

import java.util.List;
Expand All @@ -15,4 +16,5 @@ public class InsightSimpleResponseDto {
private String insightTitle;
private String insightSummary;
private List<String> insightTagList;
private FolderColor folderColor;
}
48 changes: 35 additions & 13 deletions src/main/java/goorm/reinput/insight/service/InsightService.java
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,8 @@ public List<InsightShareResponseDto> accessSharedFolder( String token) {
.map(InsightImage::getInsightImageUrl)
.collect(Collectors.toList());

Folder folder = folderRepository.findByFolderId(insight.getFolder().getFolderId()).orElseThrow(() -> new IllegalArgumentException("Folder not exists"));

return InsightShareResponseDto.builder()
.insightId(insight.getInsightId())
.insightTitle(insight.getInsightTitle())
Expand All @@ -128,6 +130,7 @@ public List<InsightShareResponseDto> accessSharedFolder( String token) {
.isCopyable(isCopyable)
.insightTagList(hashTags)
.insightImageList(insightImages)
.folderColor(folder.getFolderColor())
.build();
}).collect(Collectors.toList());

Expand Down Expand Up @@ -156,13 +159,23 @@ public List<InsightSimpleResponseDto> getInsightListByFolderAndTag(Long userId,
List<InsightSimpleResponseDto> filteredInsightList = insightList.stream()
.filter(insight -> insight.getHashTagList().stream()
.anyMatch(hashTag -> hashTag.getHashTagName().toLowerCase().contains(tag.toLowerCase())))
.map(insight -> new InsightSimpleResponseDto(
insight.getInsightId(),
insight.getInsightMainImage(),
insight.getInsightTitle(),
insight.getInsightSummary(),
insight.getHashTagList().stream().map(HashTag::getHashTagName).collect(Collectors.toList())
))
.map(insight -> {
List<String> hashTagNames = insight.getHashTagList().stream()
.map(HashTag::getHashTagName)
.collect(Collectors.toList());

// FolderColor 가져오기
FolderColor folderColor = insight.getFolder().getFolderColor();

return InsightSimpleResponseDto.builder()
.insightId(insight.getInsightId())
.insightMainImage(insight.getInsightMainImage())
.insightTitle(insight.getInsightTitle())
.insightSummary(insight.getInsightSummary())
.insightTagList(hashTagNames)
.folderColor(folderColor)
.build();
})
.collect(Collectors.toList());

return filteredInsightList;
Expand Down Expand Up @@ -256,14 +269,22 @@ public List<InsightSimpleResponseDto> getInsightList(Long userId, Long folderId)
List<Insight> insightList = insightRepository.findByInsightFolderId(folderId).orElseGet(Collections::emptyList);

return insightList.stream().map(insight -> {

List<HashTag> hashTagList = hashTagRepository.findByInsight(insight).orElseGet(Collections::emptyList);
List<String> ht = new ArrayList<>();
for (HashTag h : hashTagList) {
ht.add(h.getHashTagName());
}
List<String> ht = hashTagList.stream()
.map(HashTag::getHashTagName)
.collect(Collectors.toList());

// FolderColor 가져오기
FolderColor folderColor = insight.getFolder().getFolderColor();

return InsightSimpleResponseDto.builder().insightId(insight.getInsightId()).insightSummary(insight.getInsightSummary()).insightTitle(insight.getInsightTitle()).insightMainImage(insight.getInsightMainImage()).insightTagList(ht).build();
return InsightSimpleResponseDto.builder()
.insightId(insight.getInsightId())
.insightSummary(insight.getInsightSummary())
.insightTitle(insight.getInsightTitle())
.insightMainImage(insight.getInsightMainImage())
.insightTagList(ht)
.folderColor(folderColor) // 추가된 필드
.build();
}).collect(Collectors.toList());
}

Expand Down Expand Up @@ -310,6 +331,7 @@ public InsightResponseDto getInsightDetail(Long userId, Long insightId) {
insightImageList(insightImageNameList).
isEnable(reminder.getIsEnable()).
folderName(folder.getFolderName()).folderId(folder.getFolderId()).
folderColor(folder.getFolderColor()).
reminderQuestionList(reminderQuestionList);

if (reminder.getIsEnable()) {
Expand Down

0 comments on commit 02abb61

Please sign in to comment.