diff --git a/src/main/java/com/hatcher/haemo/recruitment/application/RecruitmentService.java b/src/main/java/com/hatcher/haemo/recruitment/application/RecruitmentService.java index f081641..b15e4aa 100644 --- a/src/main/java/com/hatcher/haemo/recruitment/application/RecruitmentService.java +++ b/src/main/java/com/hatcher/haemo/recruitment/application/RecruitmentService.java @@ -23,6 +23,8 @@ import java.util.ArrayList; import java.util.Comparator; import java.util.List; +import java.util.Set; +import java.util.stream.Collectors; import java.util.stream.Stream; import static com.hatcher.haemo.common.constants.Constant.ACTIVE; @@ -78,12 +80,15 @@ public BaseResponse getRecruitmentList(String type, boo List sortedRecruitmentList = Stream.concat(leaderRecruitmentStream, participantRecruitmentStream) .sorted(Comparator.comparing(Recruitment::getCreatedDate).reversed()) - .map(recruitment -> new RecruitmentDto(recruitment.getRecruitmentIdx(), recruitment.getType().getDescription(), recruitment.getName(), - recruitment.getLeader().getNickname(), (int) getActiveParticipantCount(recruitment)+1, recruitment.getParticipantLimit(), recruitment.getDescription(), - recruitment.getLeader().equals(user), recruitment.getStatus().equals(DONE) - //, - //recruitment.getParticipants().contains(participantRepository.findByParticipantAndRecruitmentAndStatusEquals(user, recruitment, RECRUITING)) - )).toList(); + .map(recruitment -> { + boolean isParticipating = user.getParticipants().stream() + .anyMatch(participant -> participant.getStatus().equals(ACTIVE) && participant.getRecruitment().equals(recruitment)) + || recruitment.getLeader().equals(user); + return new RecruitmentDto(recruitment.getRecruitmentIdx(), recruitment.getType().getDescription(), recruitment.getName(), + recruitment.getLeader().getNickname(), (int) getActiveParticipantCount(recruitment)+1, recruitment.getParticipantLimit(), recruitment.getDescription(), + recruitment.getLeader().equals(user), recruitment.getStatus().equals(DONE), + isParticipating); + }).toList(); recruitmentList.addAll(sortedRecruitmentList); } else { // 비회원 recruitmentList = null; @@ -115,14 +120,16 @@ private List getRecruitmentList(List recruitmentRep recruitmentList = recruitmentRepositoryList.stream() .map(recruitment -> { boolean isLeader = false; + boolean isDone = recruitment.getStatus().equals(DONE); + boolean isParticipating = false; if (finalUser != null) { isLeader = recruitment.getLeader().equals(finalUser); + isParticipating = isLeader || recruitment.getParticipants().stream() + .anyMatch(participant -> participant.getParticipant().equals(finalUser) && participant.getStatus().equals(ACTIVE)); } return new RecruitmentDto(recruitment.getRecruitmentIdx(), recruitment.getType().getDescription(), recruitment.getName(), recruitment.getLeader().getNickname(), (int) getActiveParticipantCount(recruitment)+1, recruitment.getParticipantLimit(), recruitment.getDescription(), - isLeader, false - //, recruitment.getParticipants().contains(participantRepository.findByParticipantAndRecruitmentAndStatusEquals(finalUser, recruitment, RECRUITING)) - ); + isLeader, isDone, isParticipating); }).toList(); return recruitmentList; } @@ -333,12 +340,17 @@ public BaseResponse getParticipatingList() throws BaseE .filter(participant -> participant.getStatus().equals(ACTIVE)) .map(Participant::getRecruitment); + Set participatingRecruitmentIds = user.getParticipants().stream() + .filter(participant -> participant.getStatus().equals(ACTIVE)) + .map(participant -> participant.getRecruitment().getRecruitmentIdx()) + .collect(Collectors.toSet()); + List sortedRecruitmentList = Stream.concat(leaderRecruitmentStream, participantRecruitmentStream) .sorted(Comparator.comparing(Recruitment::getCreatedDate).reversed()) .limit(3) // 상위 3개 .map(recruitment -> new RecruitmentDto(recruitment.getRecruitmentIdx(), recruitment.getType().getDescription(), recruitment.getName(), recruitment.getLeader().getNickname(), (int) getActiveParticipantCount(recruitment)+1, recruitment.getParticipantLimit(), recruitment.getDescription(), - recruitment.getLeader().equals(user), recruitment.getStatus().equals(DONE))).toList(); + recruitment.getLeader().equals(user), recruitment.getStatus().equals(DONE), participatingRecruitmentIds.contains(recruitment.getRecruitmentIdx()) || recruitment.getLeader().equals(user))).toList(); recruitmentList.addAll(sortedRecruitmentList); } else { // 비회원 recruitmentList = null; diff --git a/src/main/java/com/hatcher/haemo/recruitment/dto/RecruitmentDto.java b/src/main/java/com/hatcher/haemo/recruitment/dto/RecruitmentDto.java index ee84554..491e323 100644 --- a/src/main/java/com/hatcher/haemo/recruitment/dto/RecruitmentDto.java +++ b/src/main/java/com/hatcher/haemo/recruitment/dto/RecruitmentDto.java @@ -8,4 +8,5 @@ public record RecruitmentDto(Long recruitmentIdx, Integer participantLimit, String description, boolean isLeader, - boolean isDone) {} + boolean isDone, + boolean isParticipating) {}