diff --git a/backend/src/main/java/mouda/backend/chat/domain/Participant.java b/backend/src/main/java/mouda/backend/chat/domain/Participant.java index e8f9c33ea..be2edab2a 100644 --- a/backend/src/main/java/mouda/backend/chat/domain/Participant.java +++ b/backend/src/main/java/mouda/backend/chat/domain/Participant.java @@ -7,11 +7,13 @@ @Getter public class Participant { + private final long darakbangMemberId; private final String nickname; private final String profile; private final String role; - public Participant(String nickname, String profile, String role) { + public Participant(long darakbangMemberId, String nickname, String profile, String role) { + this.darakbangMemberId = darakbangMemberId; this.nickname = nickname; this.profile = profile; this.role = role; @@ -24,12 +26,12 @@ public boolean equals(Object o) { if (o == null || getClass() != o.getClass()) return false; Participant that = (Participant)o; - return Objects.equals(nickname, that.nickname) && Objects.equals(profile, that.profile) && Objects.equals(role, - that.role); + return darakbangMemberId == that.darakbangMemberId && Objects.equals(nickname, that.nickname) + && Objects.equals(profile, that.profile) && Objects.equals(role, that.role); } @Override public int hashCode() { - return Objects.hash(nickname, profile, role); + return Objects.hash(darakbangMemberId, nickname, profile, role); } } diff --git a/backend/src/main/java/mouda/backend/chat/implement/BetAttributeManager.java b/backend/src/main/java/mouda/backend/chat/implement/BetAttributeManager.java index 7118c0053..32631339e 100644 --- a/backend/src/main/java/mouda/backend/chat/implement/BetAttributeManager.java +++ b/backend/src/main/java/mouda/backend/chat/implement/BetAttributeManager.java @@ -43,7 +43,9 @@ private Participant getLoser(Bet bet, long requestDarakbangMemberId) { .orElseThrow(() -> new ChatException(HttpStatus.NOT_FOUND, ChatErrorMessage.BET_DARAKBANG_MEMBER_NOT_FOUND)) .getDarakbangMember(); BetRole betRole = getBetRole(requestDarakbangMemberId, bet.getMoimerId()); - return new Participant(darakbangMember.getNickname(), darakbangMember.getProfile(), betRole.toString()); + return new Participant( + darakbangMember.getId(), darakbangMember.getNickname(), darakbangMember.getProfile(), betRole.toString() + ); } private BetRole getBetRole(long requestDarakbangMemberId, long moimerId) { diff --git a/backend/src/main/java/mouda/backend/chat/implement/BetChatPreviewManager.java b/backend/src/main/java/mouda/backend/chat/implement/BetChatPreviewManager.java index db9e359f9..83895fc6c 100644 --- a/backend/src/main/java/mouda/backend/chat/implement/BetChatPreviewManager.java +++ b/backend/src/main/java/mouda/backend/chat/implement/BetChatPreviewManager.java @@ -41,7 +41,9 @@ private ChatPreview getChatPreview(BetDetails bet) { ChatRoom chatRoom = chatRoomFinder.readChatRoomByTargetId(bet.getId(), ChatRoomType.BET); long lastReadChatId = betDarakbangMemberRepository.findLastReadChatIdByBetId(targetId); List participants = betDarakbangMemberRepository.findAllByBetId(targetId).stream() - .map(betDarakbangMember -> new Participant(betDarakbangMember.getDarakbangMember().getNickname(), + .map(betDarakbangMember -> new Participant( + betDarakbangMember.getId(), + betDarakbangMember.getDarakbangMember().getNickname(), betDarakbangMember.getDarakbangMember().getProfile(), betDarakbangMember.getRole(bet.getMoimerId()))) .toList(); diff --git a/backend/src/main/java/mouda/backend/chat/implement/BetParticipantResolver.java b/backend/src/main/java/mouda/backend/chat/implement/BetParticipantResolver.java index 746203ee1..fc82fe00f 100644 --- a/backend/src/main/java/mouda/backend/chat/implement/BetParticipantResolver.java +++ b/backend/src/main/java/mouda/backend/chat/implement/BetParticipantResolver.java @@ -18,26 +18,30 @@ @RequiredArgsConstructor public class BetParticipantResolver implements ParticipantsResolver { - private final BetDarakbangMemberRepository betDarakbangMemberRepository; - - @Override - public boolean support(ChatRoomType chatRoomType) { - return chatRoomType == ChatRoomType.BET; - } - - @Override - @Transactional(readOnly = true) - public List resolve(ChatRoom chatRoom) { - return betDarakbangMemberRepository.findAllByBetId(chatRoom.getTargetId()).stream() - .map(betDarakbangMemberEntity -> { - DarakbangMember darakbangMember = betDarakbangMemberEntity.getDarakbangMember(); - BetEntity bet = betDarakbangMemberEntity.getBet(); - return new Participant(darakbangMember.getNickname(), darakbangMember.getProfile(), getBetRole(darakbangMember, bet).toString()); - }) - .toList(); - } - - private BetRole getBetRole(DarakbangMember darakbangMember, BetEntity betEntity) { - return betEntity.getMoimerId() == darakbangMember.getId() ? BetRole.MOIMER : BetRole.MOIMEE; - } + private final BetDarakbangMemberRepository betDarakbangMemberRepository; + + @Override + public boolean support(ChatRoomType chatRoomType) { + return chatRoomType == ChatRoomType.BET; + } + + @Override + @Transactional(readOnly = true) + public List resolve(ChatRoom chatRoom) { + return betDarakbangMemberRepository.findAllByBetId(chatRoom.getTargetId()).stream() + .map(betDarakbangMemberEntity -> { + DarakbangMember darakbangMember = betDarakbangMemberEntity.getDarakbangMember(); + BetEntity bet = betDarakbangMemberEntity.getBet(); + return new Participant( + darakbangMember.getId(), + darakbangMember.getNickname(), + darakbangMember.getProfile(), + getBetRole(darakbangMember, bet).toString()); + }) + .toList(); + } + + private BetRole getBetRole(DarakbangMember darakbangMember, BetEntity betEntity) { + return betEntity.getMoimerId() == darakbangMember.getId() ? BetRole.MOIMER : BetRole.MOIMEE; + } } diff --git a/backend/src/main/java/mouda/backend/chat/implement/MoimChatPreviewManager.java b/backend/src/main/java/mouda/backend/chat/implement/MoimChatPreviewManager.java index 59982a238..828178f82 100644 --- a/backend/src/main/java/mouda/backend/chat/implement/MoimChatPreviewManager.java +++ b/backend/src/main/java/mouda/backend/chat/implement/MoimChatPreviewManager.java @@ -40,7 +40,11 @@ private ChatPreview getChatPreview(Moim moim) { long lastReadChatId = chamyoRepository.findLastReadChatIdByMoimId(targetId); List participants = chamyoRepository.findAllByMoimId(targetId) .stream() - .map(chamyo -> new Participant(chamyo.getDarakbangMember().getNickname(), chamyo.getDarakbangMember().getProfile(), chamyo.getDarakbangMember().getRole().toString())) + .map(chamyo -> new Participant( + moim.getDarakbangId(), + chamyo.getDarakbangMember().getNickname(), + chamyo.getDarakbangMember().getProfile(), + chamyo.getDarakbangMember().getRole().toString())) .toList(); return ChatPreview.builder() diff --git a/backend/src/main/java/mouda/backend/chat/implement/MoimParticipantResolver.java b/backend/src/main/java/mouda/backend/chat/implement/MoimParticipantResolver.java index fc04b4151..ef17f131e 100644 --- a/backend/src/main/java/mouda/backend/chat/implement/MoimParticipantResolver.java +++ b/backend/src/main/java/mouda/backend/chat/implement/MoimParticipantResolver.java @@ -29,7 +29,11 @@ public List resolve(ChatRoom chatRoom) { return chamyoRepository.findAllByMoimId(chatRoom.getTargetId()).stream() .map(chamyo -> { DarakbangMember darakbangMember = chamyo.getDarakbangMember(); - return new Participant(darakbangMember.getNickname(), darakbangMember.getProfile(), chamyo.getMoimRole().toString()); + return new Participant( + darakbangMember.getId(), + darakbangMember.getNickname(), + darakbangMember.getProfile(), + chamyo.getMoimRole().toString()); }).toList(); } } diff --git a/backend/src/main/java/mouda/backend/chat/presentation/response/ChatRoomDetailsResponse.java b/backend/src/main/java/mouda/backend/chat/presentation/response/ChatRoomDetailsResponse.java index a661923c4..64960c485 100644 --- a/backend/src/main/java/mouda/backend/chat/presentation/response/ChatRoomDetailsResponse.java +++ b/backend/src/main/java/mouda/backend/chat/presentation/response/ChatRoomDetailsResponse.java @@ -25,7 +25,11 @@ public static ChatRoomDetailsResponse from(ChatRoomDetails chatRoomDetails) { private static List getParticipants(ChatRoomDetails chatRoomDetails) { return chatRoomDetails.getParticipants().stream() - .map(participant -> new ParticipantResponse(participant.getNickname(), participant.getProfile(), participant.getRole())) + .map(participant -> new ParticipantResponse( + participant.getDarakbangMemberId(), + participant.getNickname(), + participant.getProfile(), + participant.getRole())) .toList(); } } diff --git a/backend/src/test/java/mouda/backend/chat/implement/ChatRoomDetailsFinderTest.java b/backend/src/test/java/mouda/backend/chat/implement/ChatRoomDetailsFinderTest.java index dfda5b9da..4db2a2158 100644 --- a/backend/src/test/java/mouda/backend/chat/implement/ChatRoomDetailsFinderTest.java +++ b/backend/src/test/java/mouda/backend/chat/implement/ChatRoomDetailsFinderTest.java @@ -84,8 +84,9 @@ void find_moimChatRoomType() { assertThat(chatRoomDetails.getChatRoomType()).isEqualTo(ChatRoomType.MOIM); assertThat(chatRoomDetails.getTitle()).isEqualTo("커피 마실 사람?"); assertThat(chatRoomDetails.getId()).isEqualTo(chatRoom.getId()); - assertThat(chatRoomDetails.getParticipants()).containsExactly(new Participant("anna", "profile", "MOIMER"), - new Participant("hogee", "profile", "MOIMEE")); + assertThat(chatRoomDetails.getParticipants()).containsExactly( + new Participant(darakbangAnna.getId(), "anna", "profile", "MOIMER"), + new Participant(darakbangHogee.getId(), "hogee", "profile", "MOIMEE")); assertThat(chatRoomDetails.getAttributes()) .containsExactlyInAnyOrderEntriesOf(getExpectedMoimAttributes(savedMoim)); } @@ -129,8 +130,9 @@ void find_betChatRoomType() { assertThat(chatRoomDetails.getChatRoomType()).isEqualTo(ChatRoomType.BET); assertThat(chatRoomDetails.getTitle()).isEqualTo("테바바보"); assertThat(chatRoomDetails.getId()).isEqualTo(chatRoom.getId()); - assertThat(chatRoomDetails.getParticipants()).containsExactly(new Participant("anna", "profile", "MOIMER"), - new Participant("hogee", "profile", "MOIMEE")); + assertThat(chatRoomDetails.getParticipants()).containsExactly( + new Participant(darakbangAnna.getId(), "anna", "profile", "MOIMER"), + new Participant(darakbangHogee.getId(), "hogee", "profile", "MOIMEE")); assertThat(chatRoomDetails.getAttributes()) .containsExactlyInAnyOrderEntriesOf(getExpectedBetAttributes(savedBetEntity)); } @@ -141,6 +143,7 @@ private Map getExpectedBetAttributes(BetEntity bet) { attributes.put("isLoser", true); attributes.put("betId", bet.getId()); attributes.put("loser", new Participant( + darakbangAnna.getId(), "anna", "profile", "MOIMER"