From 379454ac56c9e586bf9adb13074ff92ba7213b0a Mon Sep 17 00:00:00 2001 From: vero <151748893+veronees@users.noreply.github.com> Date: Thu, 5 Dec 2024 20:12:35 +0900 Subject: [PATCH] =?UTF-8?q?[COZY-441]=20fix:=20=EB=A9=A4=EB=B2=84=20?= =?UTF-8?q?=EC=8A=A4=ED=83=AF=20=EC=97=86=EB=8A=94=20=EC=82=AC=EC=9A=A9?= =?UTF-8?q?=EC=9E=90=EC=97=90=20=EB=8C=80=ED=95=9C=20=EC=B0=9C=20=EC=88=98?= =?UTF-8?q?=EC=A0=95=20(#212)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * [COZY-441] fix: 멤버 스탯이 없는 사용자가 찜한 방 조회 count를 null을 반환하도록 수정한다 * [COZY-441] fix: 멤버 스탯이 없는 사용자가 다른 사용자를 찜할 수 있도록 수정한다 * [COZY-441] fix: 멤버 스탯이 없는 사용자가 찜한 사용자 목록을 조회 시 equality, color를 null로 반환하는 로직을 추가한다 --- .../dto/response/PreferenceMatchCountDTO.java | 2 +- .../service/FavoriteCommandService.java | 6 +- .../service/FavoriteQueryService.java | 32 ++++++--- .../converter/MemberStatConverter.java | 68 +++++++++++++------ 4 files changed, 72 insertions(+), 36 deletions(-) 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)