Skip to content

Commit

Permalink
[add] #147 모임 상세 조회시 참여 중 여부 필드 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
ehs208 authored and seokjun01 committed Feb 1, 2025
1 parent df15f61 commit b4b7c67
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,13 @@ public class MeetingDetailResponseDto {
private LocalDateTime dueDateTime;
private String backgroundImage;
private Boolean isOwner;
private Boolean isCurrentUser;
private List<ParticipantDto> participants;

@Builder
private MeetingDetailResponseDto(String meetingType, String meetingName, String meetingDescription,
GenderRestriction genderRestriction, String location, LocalDateTime dueDateTime,
String backgroundImage, Boolean isOwner, List<ParticipantDto> participants) {
String backgroundImage, Boolean isOwner, Boolean isCurrentUser, List<ParticipantDto> participants) {
this.meetingType = meetingType;
this.meetingName = meetingName;
this.meetingDescription = meetingDescription;
Expand All @@ -32,29 +33,35 @@ private MeetingDetailResponseDto(String meetingType, String meetingName, String
this.dueDateTime = dueDateTime;
this.backgroundImage = backgroundImage;
this.isOwner = isOwner;
this.isCurrentUser = isCurrentUser;
this.participants = participants;
}

@Getter
public static class ParticipantDto {
private Long userId;
private String name;
private String userProfileImage;
private Boolean isOwner;
private Boolean isCurrentUser;

@Builder
private ParticipantDto(Long userId, String name, Boolean isOwner, Boolean isCurrentUser) {
private ParticipantDto(Long userId, String name, Boolean isOwner, Boolean isCurrentUser,
String userProfileImage) {
this.userId = userId;
this.name = name;
this.userProfileImage = userProfileImage;
this.isOwner = isOwner;
this.isCurrentUser = isCurrentUser;
}

public static ParticipantDto createParticipantDto(Long userId, String name, Boolean isOwner,
public static ParticipantDto createParticipantDto(Long userId, String name, String userProfileImage,
Boolean isOwner,
Boolean isCurrentUser) {
return ParticipantDto.builder()
.userId(userId)
.name(name)
.userProfileImage(userProfileImage)
.isOwner(isOwner)
.isCurrentUser(isCurrentUser)
.build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -272,9 +272,9 @@ public MeetingDetailResponseDto getMeetingDetail(Long meetingId, UserDetails use
Meeting meeting = meetingRepository.findById(meetingId)
.orElseThrow(() -> new CommonException(ErrorCode.MEETING_NOT_FOUND));

Long currentUserId = securityUtils.getMember(userDetails).getMemberId();
Member member = securityUtils.getMember(userDetails);

List<MeetingDetailResponseDto.ParticipantDto> participants = getParticipants(meeting, currentUserId);
List<MeetingDetailResponseDto.ParticipantDto> participants = getParticipants(meeting, member.getMemberId());

return MeetingDetailResponseDto.builder()
.meetingType(meeting.getType())
Expand All @@ -284,7 +284,8 @@ public MeetingDetailResponseDto getMeetingDetail(Long meetingId, UserDetails use
.location(getLocation(meeting))
.dueDateTime(getDueDateTime(meeting))
.backgroundImage(Optional.ofNullable(meeting.getBackgroundImage()).map(Image::getImageUrl).orElse(null))
.isOwner(isOwner(meeting, currentUserId))
.isOwner(isOwner(meeting, member.getMemberId()))
.isCurrentUser(isCurrentUser(meeting, member))
.participants(participants)
.build();
}
Expand Down Expand Up @@ -313,6 +314,10 @@ private Boolean isOwner(Meeting meeting, Long currentUserId) {
.orElse(false);
}

private Boolean isCurrentUser(Meeting meeting, Member member) {
return meetingParticipantRepository.existsByMeetingAndMember(meeting, member);
}

private List<MeetingDetailResponseDto.ParticipantDto> getParticipants(Meeting meeting, Long currentUserId) {
return meetingParticipantRepository.findByMeeting(meeting).stream()
.sorted((p1, p2) -> {
Expand All @@ -327,6 +332,9 @@ private List<MeetingDetailResponseDto.ParticipantDto> getParticipants(Meeting me
.map(participant -> MeetingDetailResponseDto.ParticipantDto.createParticipantDto(
participant.getMember().getMemberId(),
participant.getMember().getNickname(),
Optional.ofNullable(participant.getMember().getProfileImage())
.map(Image::getImageUrl)
.orElse(null),
participant.getRole() == ParticipantRole.HOST,
participant.getMember().getMemberId().equals(currentUserId)
))
Expand Down Expand Up @@ -534,6 +542,7 @@ public void updateDeliveryMeeting(Long meetingId, UpdateDeliveryMeetingRequestDt
updateDeliveryMeetingRequestDto.getStoreName(),
updateDeliveryMeetingRequestDto.getPickupLocation(),
updateDeliveryMeetingRequestDto.getAccountNumber(),
updateDeliveryMeetingRequestDto.getBankName(),
backgroundImage
);
}
Expand Down

0 comments on commit b4b7c67

Please sign in to comment.