diff --git a/modules/study/src/main/java/kr/spot/study/application/command/WithdrawStudyService.java b/modules/study/src/main/java/kr/spot/study/application/command/WithdrawStudyService.java index f464685..a78ca44 100644 --- a/modules/study/src/main/java/kr/spot/study/application/command/WithdrawStudyService.java +++ b/modules/study/src/main/java/kr/spot/study/application/command/WithdrawStudyService.java @@ -5,6 +5,7 @@ import kr.spot.exception.GeneralException; import kr.spot.study.domain.Study; import kr.spot.study.domain.associations.StudyMember; +import kr.spot.study.domain.enums.StudyMemberStatus; import kr.spot.study.infrastructure.jpa.StudyRepository; import kr.spot.study.infrastructure.jpa.associations.StudyMemberRepository; import kr.spot.study.presentation.command.dto.request.WithdrawStudyRequest; @@ -20,7 +21,10 @@ public class WithdrawStudyService { private final StudyMemberRepository studyMemberRepository; public void withdrawStudy(long studyId, long memberId, WithdrawStudyRequest request) { - StudyMember studyMember = studyMemberRepository.getByMemberIdAndStudyId(memberId, studyId); + StudyMember studyMember = studyMemberRepository.getByMemberIdAndStudyIdAndStudyMemberStatusNot( + memberId, + studyId, + StudyMemberStatus.WITHDRAWN); Study study = studyRepository.getStudyById(studyId); StudyMember nextOwner = findNextOwner(studyId, request.nextOwnerId()); diff --git a/modules/study/src/main/java/kr/spot/study/infrastructure/jpa/associations/StudyMemberRepository.java b/modules/study/src/main/java/kr/spot/study/infrastructure/jpa/associations/StudyMemberRepository.java index 2a0ecd3..1ff705b 100644 --- a/modules/study/src/main/java/kr/spot/study/infrastructure/jpa/associations/StudyMemberRepository.java +++ b/modules/study/src/main/java/kr/spot/study/infrastructure/jpa/associations/StudyMemberRepository.java @@ -23,6 +23,15 @@ default StudyMember getByMemberIdAndStudyId(Long memberId, Long studyId) { .orElseThrow(() -> new GeneralException(ErrorStatus._STUDY_MEMBER_NOT_FOUND)); } + default StudyMember getByMemberIdAndStudyIdAndStudyMemberStatusNot(Long memberId, Long studyId, + StudyMemberStatus status) { + return findByMemberIdAndStudyIdAndStudyMemberStatusNot(memberId, studyId, status) + .orElseThrow(() -> new GeneralException(ErrorStatus._STUDY_MEMBER_NOT_FOUND)); + } + + Optional findByMemberIdAndStudyIdAndStudyMemberStatusNot(Long memberId, Long studyId, + StudyMemberStatus status); + Optional findByMemberIdAndStudyId(Long memberId, Long studyId); boolean existsByStudyIdAndMemberIdAndStudyMemberStatusIn(Long studyId, Long memberId,