Skip to content

Commit

Permalink
[COZY-441] fix: 멤버 스탯 없는 사용자에 대한 찜 수정 (#212)
Browse files Browse the repository at this point in the history
* [COZY-441] fix: 멤버 스탯이 없는 사용자가 찜한 방 조회 count를 null을 반환하도록 수정한다

* [COZY-441] fix: 멤버 스탯이 없는 사용자가 다른 사용자를 찜할 수 있도록 수정한다

* [COZY-441] fix: 멤버 스탯이 없는 사용자가 찜한 사용자 목록을 조회 시 equality, color를 null로 반환하는 로직을 추가한다
  • Loading branch information
veronees authored Dec 5, 2024
1 parent 57849d8 commit 379454a
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
@Builder
public record PreferenceMatchCountDTO(
String preferenceName,
int count
Integer count
) {

}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,18 +69,28 @@ public List<FavoriteMemberResponseDTO> getFavoriteMemberList(Member member) {
List<String> criteriaPreferences = memberStatPreferenceQueryService.getPreferencesToList(
member.getId());

MemberStat memberStat = member.getMemberStat();

List<FavoriteMemberResponseDTO> 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();

// 탈퇴한 회원이 있다면 삭제 처리
Expand Down Expand Up @@ -197,7 +207,7 @@ private List<PreferenceMatchCountDTO> getPreferenceStatsMatchCountsWithoutMember
.map(preference -> {
return PreferenceMatchCountDTO.builder()
.preferenceName(preference)
.count(0)
.count(null)
.build();
}).toList();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()))
Expand Down Expand Up @@ -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)
Expand All @@ -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();
}
Expand All @@ -140,7 +145,7 @@ public static MemberStatDifferenceListResponseDTO toMemberStatDifferenceResponse
.build();
}

Map<String, BiFunction<Member,MemberStat, Object>> fieldGetters = createFieldGetters();
Map<String, BiFunction<Member, MemberStat, Object>> fieldGetters = createFieldGetters();

// 방 초기 생성 시, 혹은 멤버 상세정보를 입력한 사람이 1명일 때
if (memberStatList.size() == 1) {
Expand Down Expand Up @@ -175,13 +180,13 @@ public static MemberStatDifferenceListResponseDTO toMemberStatDifferenceResponse
}

public static DifferenceStatus toDifferenceStatus(List<MemberStat> memberStatList, String key) {
if(memberStatList.isEmpty()) {
if (memberStatList.isEmpty()) {
return DifferenceStatus.WHITE;
}
if(memberStatList.size() == 1) {
if (memberStatList.size() == 1) {
return DifferenceStatus.WHITE;
}
Map<String, BiFunction<Member,MemberStat, Object>> fieldGetters = createFieldGetters();
Map<String, BiFunction<Member, MemberStat, Object>> fieldGetters = createFieldGetters();

return compareField(memberStatList, fieldGetters.get(key));

Expand All @@ -201,37 +206,62 @@ public static MemberStatPreferenceResponseDTO toPreferenceResponseDTO(MemberStat
// 랜덤에서 사용하는 Converter
public static List<MemberStatPreferenceDetailColorDTO> toMemberStatPreferenceDetailColorDTOList(
MemberStat memberStat, List<String> preferences
){
Map<String, Object> memberStatMap = MemberStatUtil.getMemberStatFields(memberStat, preferences);
) {
Map<String, Object> 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<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);
) {
Map<String, Object> memberStatMap = MemberStatUtil.getMemberStatFields(memberStat,
preferences);
Map<String, Object> 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<MemberStatPreferenceDetailColorDTO> toMemberStatPreferenceDetailWithoutColorDTOList(
MemberStat memberStat, List<String> preferences) {
Map<String, Object> 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)
.color(color.getValue())
.build();
}

public static MemberStatPreferenceDetailColorDTO toMemberStatPreferenceDetailWithoutColorDTO(
String stat, Object value) {
return MemberStatPreferenceDetailColorDTO.builder()
.stat(stat)
.value(value)
.build();
}

public static MemberStatRandomListResponseDTO toMemberStatRandomListDTO(
List<MemberStatPreferenceResponseDTO> memberList
) {
Expand All @@ -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)
Expand Down

0 comments on commit 379454a

Please sign in to comment.