diff --git a/src/main/java/com/cozymate/cozymate_server/domain/favorite/dto/response/PreferenceMatchCountDTO.java b/src/main/java/com/cozymate/cozymate_server/domain/favorite/dto/response/PreferenceMatchCountDTO.java index c2d03d59..8edb7854 100644 --- a/src/main/java/com/cozymate/cozymate_server/domain/favorite/dto/response/PreferenceMatchCountDTO.java +++ b/src/main/java/com/cozymate/cozymate_server/domain/favorite/dto/response/PreferenceMatchCountDTO.java @@ -5,7 +5,7 @@ @Builder public record PreferenceMatchCountDTO( String preferenceName, - int count + Integer count ) { } \ No newline at end of file diff --git a/src/main/java/com/cozymate/cozymate_server/domain/favorite/service/FavoriteCommandService.java b/src/main/java/com/cozymate/cozymate_server/domain/favorite/service/FavoriteCommandService.java index b184d800..15cf32fa 100644 --- a/src/main/java/com/cozymate/cozymate_server/domain/favorite/service/FavoriteCommandService.java +++ b/src/main/java/com/cozymate/cozymate_server/domain/favorite/service/FavoriteCommandService.java @@ -12,7 +12,6 @@ import com.cozymate.cozymate_server.domain.room.repository.RoomRepository; import com.cozymate.cozymate_server.global.response.code.status.ErrorStatus; import com.cozymate.cozymate_server.global.response.exception.GeneralException; -import java.util.Objects; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -58,13 +57,10 @@ public void deleteFavorite(Member member, Long favoriteId) { private void validTarget(FavoriteType favoriteType, Long targetId) { if (favoriteType.equals(FavoriteType.MEMBER)) { - Member member = memberRepository.findById(targetId).orElseThrow( + memberRepository.findById(targetId).orElseThrow( () -> new GeneralException(ErrorStatus._MEMBER_NOT_FOUND) ); - if (Objects.isNull(member.getMemberStat())) { - throw new GeneralException(ErrorStatus._FAVORITE_CANNOT_MEMBER_WITHOUT_MEMBERSTAT); - } } else { Room room = roomRepository.findById(targetId).orElseThrow( () -> new GeneralException(ErrorStatus._ROOM_NOT_FOUND) diff --git a/src/main/java/com/cozymate/cozymate_server/domain/favorite/service/FavoriteQueryService.java b/src/main/java/com/cozymate/cozymate_server/domain/favorite/service/FavoriteQueryService.java index 42a5beaf..e3ea01b2 100644 --- a/src/main/java/com/cozymate/cozymate_server/domain/favorite/service/FavoriteQueryService.java +++ b/src/main/java/com/cozymate/cozymate_server/domain/favorite/service/FavoriteQueryService.java @@ -69,18 +69,28 @@ public List getFavoriteMemberList(Member member) { List criteriaPreferences = memberStatPreferenceQueryService.getPreferencesToList( member.getId()); + MemberStat memberStat = member.getMemberStat(); + List favoriteMemberResponseDTOList = existFavoriteMemberList.stream() .filter(favoriteMember -> Objects.nonNull(favoriteMember.getMemberStat())) - .map(favoriteMember -> - FavoriteConverter.toFavoriteMemberResponseDTO( - memberIdFavoriteIdMap.get(favoriteMember.getId()), - MemberStatConverter.toPreferenceResponseDTO( - favoriteMember.getMemberStat(), - MemberStatConverter.toMemberStatPreferenceDetailColorDTOList( - favoriteMember.getMemberStat(), member.getMemberStat(), - criteriaPreferences - ), - equalityMap.get(favoriteMember.getId()))) + .map(favoriteMember -> { + if (Objects.isNull(memberStat)) { + return FavoriteConverter.toFavoriteMemberResponseDTO( + memberIdFavoriteIdMap.get(favoriteMember.getId()), + MemberStatConverter.toPreferenceResponseDTO( + favoriteMember.getMemberStat(), + MemberStatConverter.toMemberStatPreferenceDetailWithoutColorDTOList( + favoriteMember.getMemberStat(), criteriaPreferences), null)); + } + return FavoriteConverter.toFavoriteMemberResponseDTO( + memberIdFavoriteIdMap.get(favoriteMember.getId()), + MemberStatConverter.toPreferenceResponseDTO( + favoriteMember.getMemberStat(), + MemberStatConverter.toMemberStatPreferenceDetailColorDTOList( + favoriteMember.getMemberStat(), member.getMemberStat(), + criteriaPreferences + ), equalityMap.get(favoriteMember.getId()))); + } ).toList(); // 탈퇴한 회원이 있다면 삭제 처리 @@ -197,7 +207,7 @@ private List getPreferenceStatsMatchCountsWithoutMember .map(preference -> { return PreferenceMatchCountDTO.builder() .preferenceName(preference) - .count(0) + .count(null) .build(); }).toList(); } diff --git a/src/main/java/com/cozymate/cozymate_server/domain/memberstat/converter/MemberStatConverter.java b/src/main/java/com/cozymate/cozymate_server/domain/memberstat/converter/MemberStatConverter.java index cd943b2b..beef0504 100644 --- a/src/main/java/com/cozymate/cozymate_server/domain/memberstat/converter/MemberStatConverter.java +++ b/src/main/java/com/cozymate/cozymate_server/domain/memberstat/converter/MemberStatConverter.java @@ -67,7 +67,8 @@ public static MemberStat toEntity( } - public static MemberStatDetailResponseDTO toMemberStatDetailDTOFromEntity(MemberStat memberStat) { + public static MemberStatDetailResponseDTO toMemberStatDetailDTOFromEntity( + MemberStat memberStat) { return MemberStatDetailResponseDTO.builder() .admissionYear(MemberStatUtil.formatNumber(memberStat.getAdmissionYear())) @@ -101,13 +102,15 @@ public static MemberStatDetailResponseDTO toMemberStatDetailDTOFromEntity(Member .build(); } - public static MemberStatDetailAndRoomIdAndEqualityResponseDTO toMemberStatDetailAndRoomIdAndEqualityResponseDTO(MemberStat memberStat, + public static MemberStatDetailAndRoomIdAndEqualityResponseDTO toMemberStatDetailAndRoomIdAndEqualityResponseDTO( + MemberStat memberStat, Integer equality, Long roomId, Boolean hasRequestedRoomEntry, Long favoriteId) { return MemberStatDetailAndRoomIdAndEqualityResponseDTO.builder() - .memberDetail(MemberConverter.toMemberDetailResponseDTOFromEntity(memberStat.getMember())) + .memberDetail( + MemberConverter.toMemberDetailResponseDTOFromEntity(memberStat.getMember())) .memberStatDetail(MemberStatConverter.toMemberStatDetailDTOFromEntity(memberStat)) .equality(equality) .roomId(roomId) @@ -116,9 +119,11 @@ public static MemberStatDetailAndRoomIdAndEqualityResponseDTO toMemberStatDetail .build(); } - public static MemberStatDetailWithMemberDetailResponseDTO toMemberStatDetailWithMemberDetailDTO(MemberStat memberStat){ + public static MemberStatDetailWithMemberDetailResponseDTO toMemberStatDetailWithMemberDetailDTO( + MemberStat memberStat) { return MemberStatDetailWithMemberDetailResponseDTO.builder() - .memberDetail(MemberConverter.toMemberDetailResponseDTOFromEntity(memberStat.getMember())) + .memberDetail( + MemberConverter.toMemberDetailResponseDTOFromEntity(memberStat.getMember())) .memberStatDetail(MemberStatConverter.toMemberStatDetailDTOFromEntity(memberStat)) .build(); } @@ -140,7 +145,7 @@ public static MemberStatDifferenceListResponseDTO toMemberStatDifferenceResponse .build(); } - Map> fieldGetters = createFieldGetters(); + Map> fieldGetters = createFieldGetters(); // 방 초기 생성 시, 혹은 멤버 상세정보를 입력한 사람이 1명일 때 if (memberStatList.size() == 1) { @@ -175,13 +180,13 @@ public static MemberStatDifferenceListResponseDTO toMemberStatDifferenceResponse } public static DifferenceStatus toDifferenceStatus(List memberStatList, String key) { - if(memberStatList.isEmpty()) { + if (memberStatList.isEmpty()) { return DifferenceStatus.WHITE; } - if(memberStatList.size() == 1) { + if (memberStatList.size() == 1) { return DifferenceStatus.WHITE; } - Map> fieldGetters = createFieldGetters(); + Map> fieldGetters = createFieldGetters(); return compareField(memberStatList, fieldGetters.get(key)); @@ -201,30 +206,47 @@ public static MemberStatPreferenceResponseDTO toPreferenceResponseDTO(MemberStat // 랜덤에서 사용하는 Converter public static List toMemberStatPreferenceDetailColorDTOList( MemberStat memberStat, List preferences - ){ - Map memberStatMap = MemberStatUtil.getMemberStatFields(memberStat, preferences); + ) { + Map memberStatMap = MemberStatUtil.getMemberStatFields(memberStat, + preferences); return memberStatMap.entrySet().stream() .map(entry -> - MemberStatConverter.toMemberStatPreferenceDetailColorDTO(entry.getKey(), entry.getValue(), DifferenceStatus.WHITE)) + MemberStatConverter.toMemberStatPreferenceDetailColorDTO(entry.getKey(), + entry.getValue(), DifferenceStatus.WHITE)) .toList(); } // 일반 검색/ 필터링에서 사용하는 Converter public static List toMemberStatPreferenceDetailColorDTOList( MemberStat memberStat, MemberStat criteriaMemberStat, List preferences - ){ - Map memberStatMap = MemberStatUtil.getMemberStatFields(memberStat, preferences); - Map criteriaMemberStatMap = MemberStatUtil.getMemberStatFields(criteriaMemberStat, preferences); + ) { + Map memberStatMap = MemberStatUtil.getMemberStatFields(memberStat, + preferences); + Map criteriaMemberStatMap = MemberStatUtil.getMemberStatFields( + criteriaMemberStat, preferences); return memberStatMap.entrySet().stream() - .map(entry-> + .map(entry -> MemberStatConverter.toMemberStatPreferenceDetailColorDTO( - entry.getKey(), entry.getValue(), MemberStatUtil.compareField(entry.getValue(), criteriaMemberStatMap.get(entry.getKey()) + entry.getKey(), entry.getValue(), MemberStatUtil.compareField(entry.getValue(), + criteriaMemberStatMap.get(entry.getKey()) ))).toList(); } - public static MemberStatPreferenceDetailColorDTO toMemberStatPreferenceDetailColorDTO(String stat, Object value, DifferenceStatus color){ + public static List toMemberStatPreferenceDetailWithoutColorDTOList( + MemberStat memberStat, List preferences) { + Map memberStatMap = MemberStatUtil.getMemberStatFields(memberStat, + preferences); + + return memberStatMap.entrySet().stream() + .map(entry -> MemberStatConverter.toMemberStatPreferenceDetailWithoutColorDTO( + entry.getKey(), entry.getValue())) + .toList(); + } + + public static MemberStatPreferenceDetailColorDTO toMemberStatPreferenceDetailColorDTO( + String stat, Object value, DifferenceStatus color) { return MemberStatPreferenceDetailColorDTO.builder() .stat(stat) .value(value) @@ -232,6 +254,14 @@ public static MemberStatPreferenceDetailColorDTO toMemberStatPreferenceDetailCol .build(); } + public static MemberStatPreferenceDetailColorDTO toMemberStatPreferenceDetailWithoutColorDTO( + String stat, Object value) { + return MemberStatPreferenceDetailColorDTO.builder() + .stat(stat) + .value(value) + .build(); + } + public static MemberStatRandomListResponseDTO toMemberStatRandomListDTO( List memberList ) { @@ -242,7 +272,7 @@ public static MemberStatRandomListResponseDTO toMemberStatRandomListDTO( public static MemberStatSearchResponseDTO toMemberStatSearchResponseDTO( Member member, Integer equality - ){ + ) { return MemberStatSearchResponseDTO.builder() .memberDetail(MemberConverter.toMemberDetailResponseDTOFromEntity(member)) .equality(equality)