Skip to content

Commit

Permalink
Merge pull request #51 from goormthon-Univ/fix/15-withdraw
Browse files Browse the repository at this point in the history
[fix/15-withdraw] 리더는 띱을 나갈 수 없도록 예외처리
  • Loading branch information
JoongHyun-Kim authored Mar 23, 2024
2 parents a96da03 + 4e2aa37 commit 7ab0c85
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ public enum BaseResponseStatus {
LEADER_ROLE(false, HttpStatus.BAD_REQUEST, "리더는 띱 참여가 불가능합니다."),
NOT_LEADER_ROLE(false, HttpStatus.BAD_REQUEST, "해당 띱의 리더가 아닙니다."),
NOT_MEMBER_ROLE(false, HttpStatus.BAD_REQUEST, "해당 띱의 멤버가 아닙니다."),
LEADER_CANNOT_WITHDRAW(false, HttpStatus.BAD_REQUEST, "띱의 리더는 나갈 수 없습니다."),

// comment(2200-2299)
INVALID_COMMENT_IDX(false, HttpStatus.NOT_FOUND, "해당 comment idx로 comment를 찾을 수 없습니다."),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,10 @@ public BaseResponse<RecruitmentListResponse> getRecruitmentList(String type, boo
.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))).toList();
recruitment.getLeader().equals(user), recruitment.getStatus().equals(DONE)
//,
//recruitment.getParticipants().contains(participantRepository.findByParticipantAndRecruitmentAndStatusEquals(user, recruitment, RECRUITING))
)).toList();
recruitmentList.addAll(sortedRecruitmentList);
} else { // 비회원
recruitmentList = null;
Expand Down Expand Up @@ -117,7 +120,9 @@ private List<RecruitmentDto> getRecruitmentList(List<Recruitment> recruitmentRep
}
return new RecruitmentDto(recruitment.getRecruitmentIdx(), recruitment.getType().getDescription(), recruitment.getName(),
recruitment.getLeader().getNickname(), (int) getActiveParticipantCount(recruitment)+1, recruitment.getParticipantLimit(), recruitment.getDescription(),
isLeader, false);
isLeader, false
//, recruitment.getParticipants().contains(participantRepository.findByParticipantAndRecruitmentAndStatusEquals(finalUser, recruitment, RECRUITING))
);
}).toList();
return recruitmentList;
}
Expand Down Expand Up @@ -284,6 +289,7 @@ public BaseResponse<String> withdrawRecruitment(Long recruitmentIdx) throws Base
try {
User user = userRepository.findById(userService.getUserIdxWithValidation()).orElseThrow(() -> new BaseException(INVALID_USER_IDX));
Recruitment recruitment = recruitmentRepository.findById(recruitmentIdx).orElseThrow(() -> new BaseException(INVALID_RECRUITMENT_IDX));
if (recruitment.getLeader().equals(user)) throw new BaseException(LEADER_CANNOT_WITHDRAW);
boolean isParticipant = recruitment.getParticipants().stream().anyMatch(participant -> participant.getParticipant().equals(user));
if (!isParticipant) throw new BaseException(NOT_MEMBER_ROLE);
validateRecruitmentStatus(recruitment.getStatus().equals(DONE), ALREADY_DONE_RECRUITMENT);
Expand Down

0 comments on commit 7ab0c85

Please sign in to comment.