Skip to content

Commit

Permalink
Merge pull request #740 from woowacourse-teams/feat/#737
Browse files Browse the repository at this point in the history
다락방 멤버 프로필 조회 기능 구현
  • Loading branch information
ay-eonii authored Oct 24, 2024
2 parents c91dd2d + 94d4e7d commit 9545dd7
Show file tree
Hide file tree
Showing 19 changed files with 149 additions and 42 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 @@ -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());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,11 @@ public static ChatPreviewResponse toResponse(ChatPreview chatPreview) {

private static List<ParticipantResponse> 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();
}
}
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
@@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -79,4 +80,15 @@ public ResponseEntity<Void> updateMyInfo(

return ResponseEntity.ok().build();
}

@GetMapping("/{darakbangId}/members/{darakbangMemberId}/profile")
public ResponseEntity<RestResponse<DarakbangMemberProfileResponse>> findProfile(
@PathVariable Long darakbangId,
@PathVariable Long darakbangMemberId,
@LoginDarakbangMember DarakbangMember darakbangMember
) {
DarakbangMemberProfileResponse response = darakbangMemberService.findProfile(darakbangMemberId);

return ResponseEntity.ok().body(new RestResponse<>(response));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -58,4 +59,16 @@ ResponseEntity<Void> updateMyInfo(
@RequestPart String nickname,
@RequestPart String description
);

@Operation(summary = "다락방 멤버 프로필 조회", description = "다락방 멤버의 프로필을 조회한다.")
@ApiResponses({
@ApiResponse(responseCode = "200", description = "마이페이지 수정 성공!"),
@ApiResponse(responseCode = "404", description = "존재하지 않는 다락방 멤버입니다."),
@ApiResponse(responseCode = "404", description = "회원가입 이력을 찾을 수 없습니다.")
})
ResponseEntity<RestResponse<DarakbangMemberProfileResponse>> findProfile(
@PathVariable Long darakbangId,
@PathVariable Long darakbangMemberId,
@LoginDarakbangMember DarakbangMember darakbangMember
);
}
Original file line number Diff line number Diff line change
@@ -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();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,15 @@

@Builder
public record ChamyoFindAllResponse(
long darakbangMemberId,
String nickname,
String profile,
String role
) {

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())
Expand Down
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
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
}

0 comments on commit 9545dd7

Please sign in to comment.