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

[COZY-410] 룸메이트 추천, 필터링, 상세 필터링 color 리턴 #194

Merged
merged 3 commits into from
Nov 30, 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
Expand Up @@ -70,15 +70,16 @@ public List<FavoriteMemberResponseDTO> getFavoriteMemberList(Member member) {

List<FavoriteMemberResponseDTO> favoriteMemberResponseDTOList = existFavoriteMemberList.stream()
.filter(favoriteMember -> Objects.nonNull(favoriteMember.getMemberStat()))
.map(favoriteMember -> {
Map<String, Object> preferences = MemberStatUtil.getMemberStatFields(
favoriteMember.getMemberStat(), criteriaPreferences);

return FavoriteConverter.toFavoriteMemberResponseDTO(
.map(favoriteMember ->
FavoriteConverter.toFavoriteMemberResponseDTO(
memberIdFavoriteIdMap.get(favoriteMember.getId()),
MemberStatConverter.toPreferenceResponseDTO(favoriteMember.getMemberStat(),
preferences, equalityMap.get(favoriteMember.getId())));
}).toList();
MemberStatConverter.toPreferenceResponseDTO(
favoriteMember.getMemberStat(),
MemberStatConverter.toMemberStatPreferenceDetailColorDTOList(
member.getMemberStat(), favoriteMember.getMemberStat(), criteriaPreferences
),
equalityMap.get(favoriteMember.getId())))
).toList();

// 탈퇴한 회원이 있다면 삭제 처리
deleteFavoriteMember(findFavoriteMemberIdList, existFavoriteMemberList);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import com.cozymate.cozymate_server.domain.member.converter.MemberConverter;
import com.cozymate.cozymate_server.domain.memberstat.MemberStat;
import com.cozymate.cozymate_server.domain.memberstat.MemberStat.MemberStatBuilder;
import com.cozymate.cozymate_server.domain.memberstat.dto.response.MemberStatPreferenceDetailColorDTO;
import com.cozymate.cozymate_server.domain.memberstat.dto.response.MemberStatDetailAndRoomIdAndEqualityResponseDTO;
import com.cozymate.cozymate_server.domain.memberstat.dto.response.MemberStatDetailWithMemberDetailResponseDTO;
import com.cozymate.cozymate_server.domain.memberstat.dto.response.MemberStatDifferenceListResponseDTO;
Expand Down Expand Up @@ -187,7 +188,7 @@ public static DifferenceStatus toDifferenceStatus(List<MemberStat> memberStatLis
}

public static MemberStatPreferenceResponseDTO toPreferenceResponseDTO(MemberStat stat,
Map<String, Object> preferences, Integer equality) {
List<MemberStatPreferenceDetailColorDTO> preferences, Integer equality) {

return MemberStatPreferenceResponseDTO.builder()
.memberDetail(MemberConverter.toMemberDetailResponseDTOFromEntity(stat.getMember()))
Expand All @@ -196,6 +197,41 @@ public static MemberStatPreferenceResponseDTO toPreferenceResponseDTO(MemberStat
.build();
}


// 랜덤에서 사용하는 Converter
public static List<MemberStatPreferenceDetailColorDTO> toMemberStatPreferenceDetailColorDTOList(
MemberStat memberStat, List<String> preferences
){
Map<String, Object> memberStatMap = MemberStatUtil.getMemberStatFields(memberStat, preferences);

return memberStatMap.entrySet().stream()
.map(entry ->
MemberStatConverter.toMemberStatPreferenceDetailColorDTO(entry.getKey(), entry.getValue(), DifferenceStatus.WHITE))
.toList();
}

// 일반 검색/ 필터링에서 사용하는 Converter
public static List<MemberStatPreferenceDetailColorDTO> toMemberStatPreferenceDetailColorDTOList(
MemberStat memberStat, MemberStat criteriaMemberStat, List<String> preferences
){
Map<String, Object> memberStatMap = MemberStatUtil.getMemberStatFields(memberStat, preferences);
Map<String, Object> criteriaMemberStatMap = MemberStatUtil.getMemberStatFields(criteriaMemberStat, preferences);

return memberStatMap.entrySet().stream()
.map(entry->
MemberStatConverter.toMemberStatPreferenceDetailColorDTO(
entry.getKey(), entry.getValue(), MemberStatUtil.compareField(entry.getValue(), criteriaMemberStatMap.get(entry.getKey())
))).toList();
}

public static MemberStatPreferenceDetailColorDTO toMemberStatPreferenceDetailColorDTO(String stat, Object value, DifferenceStatus color){
return MemberStatPreferenceDetailColorDTO.builder()
.stat(stat)
.value(value)
.color(color.getValue())
.build();
}

Comment on lines +200 to +234
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

빡세게 계층화 했습니다

public static MemberStatRandomListResponseDTO toMemberStatRandomListDTO(
List<MemberStatPreferenceResponseDTO> memberList
) {
Expand Down
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

새로운 DTO를 만들었슴다

Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.cozymate.cozymate_server.domain.memberstat.dto.response;

import com.cozymate.cozymate_server.domain.memberstat.enums.DifferenceStatus;
import lombok.Builder;

@Builder
public record MemberStatPreferenceDetailColorDTO(
String stat,
// 다양한 Stat 값이 들어갈 수 있어 Object로 정의.
Object value,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

주석으로 어떤 이유에서 Object를 사용하는지 적어주면 알아보기 편할 것 같습니당
왜 오브젝트를 쓰지? 했는데, 멤버스탯이었군요...

String color
) {

}
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
package com.cozymate.cozymate_server.domain.memberstat.dto.response;

import com.cozymate.cozymate_server.domain.member.dto.response.MemberDetailResponseDTO;
import java.util.Map;
import java.util.List;
import lombok.Builder;

@Builder
public record MemberStatPreferenceResponseDTO(
MemberDetailResponseDTO memberDetail,
Integer equality,
Map<String,Object> preferenceStats
List<MemberStatPreferenceDetailColorDTO> preferenceStats
) {

}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
import com.cozymate.cozymate_server.domain.memberstat.dto.response.MemberStatRandomListResponseDTO;
import com.cozymate.cozymate_server.domain.memberstat.dto.response.MemberStatSearchResponseDTO;
import com.cozymate.cozymate_server.domain.memberstat.repository.MemberStatRepository;
import com.cozymate.cozymate_server.domain.memberstat.util.MemberStatUtil;
import com.cozymate.cozymate_server.domain.memberstatequality.service.MemberStatEqualityQueryService;
import com.cozymate.cozymate_server.domain.memberstatpreference.service.MemberStatPreferenceQueryService;
import com.cozymate.cozymate_server.domain.room.enums.RoomStatus;
Expand Down Expand Up @@ -139,7 +138,7 @@ public MemberStatPageResponseDTO<List<?>> getMemberStatList(Member member,
return createEmptyPageResponse(pageable);
}

return toPageResponseDto(createMemberStatPreferenceResponse(filteredResult,criteriaMemberStat.getMember()));
return toPageResponseDto(createMemberStatPreferenceResponse(filteredResult,criteriaMemberStat));

}

Expand All @@ -156,7 +155,7 @@ public MemberStatPageResponseDTO<List<?>> getSearchedAndFilteredMemberStatList(M
return createEmptyPageResponse(pageable);
}

return toPageResponseDto(createMemberStatPreferenceResponse(filteredResult,criteriaMemberStat.getMember()));
return toPageResponseDto(createMemberStatPreferenceResponse(filteredResult,criteriaMemberStat));
}

public Integer getNumOfSearchedAndFilteredMemberStatList(Member member,
Expand Down Expand Up @@ -194,15 +193,11 @@ public MemberStatRandomListResponseDTO getRandomMemberStatWithPreferences(Member

// 선택된 멤버들에 대해 MemberStatPreferenceResponseDTO 리스트 생성
List<MemberStatPreferenceResponseDTO> preferenceResponseList = randomMemberStats.stream()
.map(stat -> {
Map<String, Object> preferences = MemberStatUtil.getMemberStatFields(stat,
criteriaPreferences);
return MemberStatConverter.toPreferenceResponseDTO(
stat,
preferences,
NO_EQUALITY
);
})
.map(stat ->
MemberStatConverter.toPreferenceResponseDTO(stat,
MemberStatConverter.toMemberStatPreferenceDetailColorDTOList(stat,criteriaPreferences),
NO_EQUALITY)
)
.toList();

return MemberStatConverter.toMemberStatRandomListDTO(
Expand All @@ -211,21 +206,18 @@ public MemberStatRandomListResponseDTO getRandomMemberStatWithPreferences(Member
}

public Slice<MemberStatPreferenceResponseDTO> createMemberStatPreferenceResponse(
Slice<Map<MemberStat, Integer>> filteredResult, Member criteriaMember) {

Slice<Map<MemberStat, Integer>> filteredResult, MemberStat criteriaMemberStat) {
return filteredResult.map(
memberStatIntegerMap ->{
Map.Entry<MemberStat, Integer> entry = memberStatIntegerMap.entrySet().iterator()
.next();
MemberStat memberStat = entry.getKey();
Integer equality = entry.getValue();
List<String> criteriaPreferences = memberStatPreferenceQueryService.getPreferencesToList(
criteriaMember.getId());
Map<String,Object> preferences = MemberStatUtil.getMemberStatFields(memberStat,
criteriaPreferences);
criteriaMemberStat.getMember().getId());
return MemberStatConverter.toPreferenceResponseDTO(
memberStat,
preferences,
MemberStatConverter.toMemberStatPreferenceDetailColorDTOList(memberStat,criteriaMemberStat,criteriaPreferences),
equality
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.function.BiFunction;
import java.util.stream.Collectors;

Expand Down Expand Up @@ -56,6 +57,14 @@ public static <T> DifferenceStatus compareField(List<MemberStat> memberStatList,
}
}

public static DifferenceStatus compareField(
Object memberStatMapValue, Object criteriaMemberStatValue){
if(memberStatMapValue.equals(criteriaMemberStatValue)){
return DifferenceStatus.BLUE;
}
return DifferenceStatus.RED;
}

Comment on lines +60 to +67
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

새로 만든 비교 메서드임다


// 아래부터는 특정 멤버스탯을 가져오기 위한 Util들
public static Map<String, BiFunction<Member,MemberStat,Object>> createFieldGetters() {
Expand Down Expand Up @@ -110,6 +119,8 @@ public static Map<String, Object> getMemberStatFields(MemberStat memberStat, Lis
return result;
}



// 학번 Response 위해 필요한 Util
public static String formatNumber(int number) {
return String.format("%02d", number);
Expand Down