Skip to content
Open
Original file line number Diff line number Diff line change
Expand Up @@ -75,4 +75,30 @@ public void acceptJoinRequest(Long studyId, Long requestId, Long memberId) {
joinRequest.accept();
}

@Transactional
public void rejectJoinRequest(Long studyId, Long requestId, Long memberId) {
if (!studyRepository.existsById(studyId)) {
throw new StudyNotFoundException("스터디를 찾을 수 없습니다.");
}

MemberStudy memberStudy = memberStudyRepository.findByStudyIdAndMemberId(studyId, memberId)
.orElseThrow(() -> new ForbiddenException("스터디 멤버가 아닙니다."));

if (!memberStudy.isLeader()) {
throw new ForbiddenException("수락 권한이 없습니다.");
}

JoinRequest joinRequest = joinRequestRepository.findById(requestId)
.orElseThrow(() -> new JoinRequestNotFoundException("JoinRequest를 찾을 수 없습니다."));

if (!joinRequest.validateStudyIdMatch(studyId)) {
throw new StudyMismatchException("요청한 스터디 ID와 가입 요청의 스터디 ID가 일치하지 않습니다");
}

if (!joinRequest.isWaiting()) {
throw new JoinRequestAlreadyHandledException("이미 처리된 요청입니다.");
}
joinRequest.reject();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,12 @@ public boolean accept() {
return true;
}

public void reject() {

public boolean reject() {
if (!isWaiting()) {
return false;
}
this.state = JoinRequestState.REJECT;
return true;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,15 @@ public ResponseEntity<Void> acceptJoinRequest(
return ResponseEntity.ok(null);
}

@PatchMapping("/api/v1/studies/{studyId}/join-requests/{requestId}/reject")
public ResponseEntity<Void> rejectJoinRequest(
@PathVariable Long studyId,
@PathVariable Long requestId,
@SignIn SessionMember sessionMember
) {
joinRequestCrudService.rejectJoinRequest(studyId, requestId, sessionMember.id());

return ResponseEntity.ok(null);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

바디가 없으면 .ok().build() 하면 됩니당!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

감사합니다. 고쳤어요!

}

}