Skip to content

Commit

Permalink
Merge pull request #53 from goormthon-Univ/develop
Browse files Browse the repository at this point in the history
[develop] main merge
  • Loading branch information
JoongHyun-Kim committed Mar 23, 2024
2 parents 7ab0c85 + 1c46a7d commit 49d602d
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -78,12 +80,15 @@ public BaseResponse<RecruitmentListResponse> getRecruitmentList(String type, boo

List<RecruitmentDto> 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;
Expand Down Expand Up @@ -115,14 +120,16 @@ private List<RecruitmentDto> getRecruitmentList(List<Recruitment> 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;
}
Expand Down Expand Up @@ -333,12 +340,17 @@ public BaseResponse<RecruitmentListResponse> getParticipatingList() throws BaseE
.filter(participant -> participant.getStatus().equals(ACTIVE))
.map(Participant::getRecruitment);

Set<Long> participatingRecruitmentIds = user.getParticipants().stream()
.filter(participant -> participant.getStatus().equals(ACTIVE))
.map(participant -> participant.getRecruitment().getRecruitmentIdx())
.collect(Collectors.toSet());

List<RecruitmentDto> 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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@ public record RecruitmentDto(Long recruitmentIdx,
Integer participantLimit,
String description,
boolean isLeader,
boolean isDone) {}
boolean isDone,
boolean isParticipating) {}

0 comments on commit 49d602d

Please sign in to comment.