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/ChatFindDetailResponse.java b/backend/src/main/java/mouda/backend/chat/presentation/response/ChatFindDetailResponse.java index 2b1bf7bc5..a9c7196a4 100644 --- a/backend/src/main/java/mouda/backend/chat/presentation/response/ChatFindDetailResponse.java +++ b/backend/src/main/java/mouda/backend/chat/presentation/response/ChatFindDetailResponse.java @@ -34,6 +34,6 @@ public static ChatFindDetailResponse toResponse(ChatOwnership chatOwnership) { private static ParticipantResponse getParticipantResponse(ChatOwnership chatOwnership) { Author author = chatOwnership.getChat().getAuthor(); - return new ParticipantResponse(author.getNickname(), author.getProfile()); + return new ParticipantResponse(author.getDarakbangMemberId(), author.getNickname(), author.getProfile()); } } diff --git a/backend/src/main/java/mouda/backend/chat/presentation/response/ChatPreviewResponse.java b/backend/src/main/java/mouda/backend/chat/presentation/response/ChatPreviewResponse.java index eac3eaa48..6928d9002 100644 --- a/backend/src/main/java/mouda/backend/chat/presentation/response/ChatPreviewResponse.java +++ b/backend/src/main/java/mouda/backend/chat/presentation/response/ChatPreviewResponse.java @@ -30,7 +30,11 @@ public static ChatPreviewResponse toResponse(ChatPreview chatPreview) { private static List getParticipants(ChatPreview chatPreview) { return chatPreview.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/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/main/java/mouda/backend/chat/presentation/response/ParticipantResponse.java b/backend/src/main/java/mouda/backend/chat/presentation/response/ParticipantResponse.java index ea1d1ddcd..caf4944e0 100644 --- a/backend/src/main/java/mouda/backend/chat/presentation/response/ParticipantResponse.java +++ b/backend/src/main/java/mouda/backend/chat/presentation/response/ParticipantResponse.java @@ -1,12 +1,13 @@ package mouda.backend.chat.presentation.response; public record ParticipantResponse( + long darakbangMemberId, String nickname, String profile, String role ) { - public ParticipantResponse(String nickname, String profile) { - this(nickname, profile, null); + public ParticipantResponse(long darakbangMemberId, String nickname, String profile) { + this(darakbangMemberId, nickname, profile, null); } } diff --git a/backend/src/main/java/mouda/backend/darakbangmember/business/DarakbangMemberService.java b/backend/src/main/java/mouda/backend/darakbangmember/business/DarakbangMemberService.java index 7c2b82c3d..5f7bae81c 100644 --- a/backend/src/main/java/mouda/backend/darakbangmember/business/DarakbangMemberService.java +++ b/backend/src/main/java/mouda/backend/darakbangmember/business/DarakbangMemberService.java @@ -14,6 +14,7 @@ import mouda.backend.darakbangmember.implement.DarakbangMemberWriter; import mouda.backend.darakbangmember.implement.ImageParser; import mouda.backend.darakbangmember.implement.S3Client; +import mouda.backend.darakbangmember.presentation.response.DarakbangMemberProfileResponse; import mouda.backend.darakbangmember.presentation.response.DarakbangMemberResponses; import mouda.backend.darakbangmember.presentation.response.DarakbangMemberRoleResponse; import mouda.backend.member.domain.Member; @@ -82,4 +83,12 @@ private void deleteProfile(DarakbangMember darakbangMember) { s3Client.deleteFile(darakbangMember.getProfile()); } } + + @Transactional(readOnly = true) + public DarakbangMemberProfileResponse findProfile(long darakbangMemberId) { + DarakbangMember darakbangMember = darakbangMemberFinder.find(darakbangMemberId); + Member member = memberFinder.findByMemberId(darakbangMember.getMemberId()); + + return DarakbangMemberProfileResponse.toResponse(darakbangMember, member.getName()); + } } diff --git a/backend/src/main/java/mouda/backend/darakbangmember/implement/DarakbangMemberFinder.java b/backend/src/main/java/mouda/backend/darakbangmember/implement/DarakbangMemberFinder.java index 2bb374f50..e0118dae0 100644 --- a/backend/src/main/java/mouda/backend/darakbangmember/implement/DarakbangMemberFinder.java +++ b/backend/src/main/java/mouda/backend/darakbangmember/implement/DarakbangMemberFinder.java @@ -49,4 +49,10 @@ public DarakBangMemberRole findDarakbangMemberRole(Long darakbangId, Long member } return DarakBangMemberRole.OUTSIDER; } + + public DarakbangMember find(long darakbangMemberId) { + return darakbangMemberRepository.findById(darakbangMemberId) + .orElseThrow( + () -> new DarakbangMemberException(HttpStatus.NOT_FOUND, DarakbangMemberErrorMessage.MEMBER_NOT_EXIST)); + } } diff --git a/backend/src/main/java/mouda/backend/darakbangmember/presentation/controller/DarakbangMemberController.java b/backend/src/main/java/mouda/backend/darakbangmember/presentation/controller/DarakbangMemberController.java index 4453aa777..3fcbe913f 100644 --- a/backend/src/main/java/mouda/backend/darakbangmember/presentation/controller/DarakbangMemberController.java +++ b/backend/src/main/java/mouda/backend/darakbangmember/presentation/controller/DarakbangMemberController.java @@ -18,6 +18,7 @@ import mouda.backend.darakbangmember.business.DarakbangMemberService; import mouda.backend.darakbangmember.domain.DarakbangMember; import mouda.backend.darakbangmember.presentation.controller.swagger.DarakbangMemberSwagger; +import mouda.backend.darakbangmember.presentation.response.DarakbangMemberProfileResponse; import mouda.backend.darakbangmember.presentation.response.DarakbangMemberResponses; import mouda.backend.darakbangmember.presentation.response.DarakbangMemberRoleResponse; import mouda.backend.member.domain.Member; @@ -79,4 +80,15 @@ public ResponseEntity updateMyInfo( return ResponseEntity.ok().build(); } + + @GetMapping("/{darakbangId}/members/{darakbangMemberId}/profile") + public ResponseEntity> findProfile( + @PathVariable Long darakbangId, + @PathVariable Long darakbangMemberId, + @LoginDarakbangMember DarakbangMember darakbangMember + ) { + DarakbangMemberProfileResponse response = darakbangMemberService.findProfile(darakbangMemberId); + + return ResponseEntity.ok().body(new RestResponse<>(response)); + } } diff --git a/backend/src/main/java/mouda/backend/darakbangmember/presentation/controller/swagger/DarakbangMemberSwagger.java b/backend/src/main/java/mouda/backend/darakbangmember/presentation/controller/swagger/DarakbangMemberSwagger.java index 3916a2fe3..b28aae545 100644 --- a/backend/src/main/java/mouda/backend/darakbangmember/presentation/controller/swagger/DarakbangMemberSwagger.java +++ b/backend/src/main/java/mouda/backend/darakbangmember/presentation/controller/swagger/DarakbangMemberSwagger.java @@ -12,6 +12,7 @@ import mouda.backend.common.config.argumentresolver.LoginMember; import mouda.backend.common.response.RestResponse; import mouda.backend.darakbangmember.domain.DarakbangMember; +import mouda.backend.darakbangmember.presentation.response.DarakbangMemberProfileResponse; import mouda.backend.darakbangmember.presentation.response.DarakbangMemberResponses; import mouda.backend.darakbangmember.presentation.response.DarakbangMemberRoleResponse; import mouda.backend.member.domain.Member; @@ -58,4 +59,16 @@ ResponseEntity updateMyInfo( @RequestPart String nickname, @RequestPart String description ); + + @Operation(summary = "다락방 멤버 프로필 조회", description = "다락방 멤버의 프로필을 조회한다.") + @ApiResponses({ + @ApiResponse(responseCode = "200", description = "마이페이지 수정 성공!"), + @ApiResponse(responseCode = "404", description = "존재하지 않는 다락방 멤버입니다."), + @ApiResponse(responseCode = "404", description = "회원가입 이력을 찾을 수 없습니다.") + }) + ResponseEntity> findProfile( + @PathVariable Long darakbangId, + @PathVariable Long darakbangMemberId, + @LoginDarakbangMember DarakbangMember darakbangMember + ); } diff --git a/backend/src/main/java/mouda/backend/darakbangmember/presentation/response/DarakbangMemberProfileResponse.java b/backend/src/main/java/mouda/backend/darakbangmember/presentation/response/DarakbangMemberProfileResponse.java new file mode 100644 index 000000000..95cf041e1 --- /dev/null +++ b/backend/src/main/java/mouda/backend/darakbangmember/presentation/response/DarakbangMemberProfileResponse.java @@ -0,0 +1,22 @@ +package mouda.backend.darakbangmember.presentation.response; + +import lombok.Builder; +import mouda.backend.darakbangmember.domain.DarakbangMember; + +@Builder +public record DarakbangMemberProfileResponse( + String name, + String nickname, + String profile, + String description +) { + + public static DarakbangMemberProfileResponse toResponse(DarakbangMember darakbangMember, String name) { + return DarakbangMemberProfileResponse.builder() + .name(name) + .nickname(darakbangMember.getNickname()) + .profile(darakbangMember.getProfile()) + .description(darakbangMember.getDescription()) + .build(); + } +} diff --git a/backend/src/main/java/mouda/backend/darakbangmember/presentation/response/DarakbangMemberResponse.java b/backend/src/main/java/mouda/backend/darakbangmember/presentation/response/DarakbangMemberResponse.java index 908b33de3..51ce4a42d 100644 --- a/backend/src/main/java/mouda/backend/darakbangmember/presentation/response/DarakbangMemberResponse.java +++ b/backend/src/main/java/mouda/backend/darakbangmember/presentation/response/DarakbangMemberResponse.java @@ -5,16 +5,16 @@ @Builder public record DarakbangMemberResponse( - long memberId, + long darakbangMemberId, String nickname, String profile ) { public static DarakbangMemberResponse toResponse(DarakbangMember darakbangMember) { return DarakbangMemberResponse.builder() - .memberId(darakbangMember.getMemberId()) + .darakbangMemberId(darakbangMember.getId()) .nickname(darakbangMember.getNickname()) - .profile("") + .profile(darakbangMember.getProfile()) .build(); } } diff --git a/backend/src/main/java/mouda/backend/moim/presentation/response/chamyo/ChamyoFindAllResponse.java b/backend/src/main/java/mouda/backend/moim/presentation/response/chamyo/ChamyoFindAllResponse.java index 7a96c93c7..a5e9fbaa2 100644 --- a/backend/src/main/java/mouda/backend/moim/presentation/response/chamyo/ChamyoFindAllResponse.java +++ b/backend/src/main/java/mouda/backend/moim/presentation/response/chamyo/ChamyoFindAllResponse.java @@ -5,6 +5,7 @@ @Builder public record ChamyoFindAllResponse( + long darakbangMemberId, String nickname, String profile, String role @@ -12,6 +13,7 @@ public record ChamyoFindAllResponse( public static ChamyoFindAllResponse toResponse(Chamyo chamyo) { return ChamyoFindAllResponse.builder() + .darakbangMemberId(chamyo.getDarakbangMember().getId()) .nickname(chamyo.getDarakbangMember().getNickname()) .profile(chamyo.getDarakbangMember().getProfile()) .role(chamyo.getMoimRole().name()) 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" diff --git a/backend/src/test/java/mouda/backend/darakbangmember/implement/DarakbangMemberFinderTest.java b/backend/src/test/java/mouda/backend/darakbangmember/implement/DarakbangMemberFinderTest.java index b011eeea3..fdb8a19c5 100644 --- a/backend/src/test/java/mouda/backend/darakbangmember/implement/DarakbangMemberFinderTest.java +++ b/backend/src/test/java/mouda/backend/darakbangmember/implement/DarakbangMemberFinderTest.java @@ -114,4 +114,17 @@ void findDarakbangMember_notFound() { .hasMessage(DarakbangMemberErrorMessage.MEMBER_NOT_EXIST.getMessage()) .hasFieldOrPropertyWithValue("httpStatus", HttpStatus.UNAUTHORIZED); } + + @Test + @DisplayName("다락방멤버 Id로 다락방 멤버를 조회한다.") + void findDarakbangMember() { + Member hogee = memberRepository.save(MemberFixture.getHogee()); + Darakbang wooteco = darakbangRepository.save(DarakbangFixture.getDarakbangWithWooteco()); + DarakbangMember darakbangMember = darakbangMemberRepository.save( + DarakbangMemberFixture.getDarakbangMemberWithWooteco(wooteco, hogee)); + + DarakbangMember foundDarakbangMember = darakbangMemberFinder.find(darakbangMember.getId()); + + assertThat(foundDarakbangMember.getNickname()).isEqualTo(darakbangMember.getNickname()); + } }