Skip to content

Commit

Permalink
feat: Participant에 DarakbangMemberId 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
ay-eonii committed Oct 23, 2024
1 parent ee2217b commit a1f480a
Show file tree
Hide file tree
Showing 8 changed files with 60 additions and 35 deletions.
10 changes: 6 additions & 4 deletions backend/src/main/java/mouda/backend/chat/domain/Participant.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,9 @@ private ChatPreview getChatPreview(BetDetails bet) {
ChatRoom chatRoom = chatRoomFinder.readChatRoomByTargetId(bet.getId(), ChatRoomType.BET);
long lastReadChatId = betDarakbangMemberRepository.findLastReadChatIdByBetId(targetId);
List<Participant> 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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<Participant> 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<Participant> 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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,11 @@ private ChatPreview getChatPreview(Moim moim) {
long lastReadChatId = chamyoRepository.findLastReadChatIdByMoimId(targetId);
List<Participant> 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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,11 @@ public List<Participant> 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();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,11 @@ public static ChatRoomDetailsResponse from(ChatRoomDetails chatRoomDetails) {

private static List<ParticipantResponse> 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();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
Expand Down Expand Up @@ -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));
}
Expand All @@ -141,6 +143,7 @@ private Map<String, Object> getExpectedBetAttributes(BetEntity bet) {
attributes.put("isLoser", true);
attributes.put("betId", bet.getId());
attributes.put("loser", new Participant(
darakbangAnna.getId(),
"anna",
"profile",
"MOIMER"
Expand Down

0 comments on commit a1f480a

Please sign in to comment.