Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package kr.spot.study.application.command;

import jakarta.transaction.Transactional;
import java.util.List;
import kr.spot.code.status.ErrorStatus;
import kr.spot.exception.GeneralException;
import kr.spot.study.domain.Study;
Expand All @@ -21,10 +22,10 @@ public class WithdrawStudyService {
private final StudyMemberRepository studyMemberRepository;

public void withdrawStudy(long studyId, long memberId, WithdrawStudyRequest request) {
StudyMember studyMember = studyMemberRepository.getByMemberIdAndStudyIdAndStudyMemberStatusNot(
StudyMember studyMember = studyMemberRepository.getByMemberIdAndStudyIdAndStudyMemberStatusIn(
memberId,
studyId,
StudyMemberStatus.WITHDRAWN);
List.of(StudyMemberStatus.APPROVED, StudyMemberStatus.OWNER));
Study study = studyRepository.getStudyById(studyId);

StudyMember nextOwner = findNextOwner(studyId, request.nextOwnerId());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,14 @@ 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)
default StudyMember getByMemberIdAndStudyIdAndStudyMemberStatusIn(Long memberId, Long studyId,
List<StudyMemberStatus> studyMemberStatuses) {
return findByMemberIdAndStudyIdAndStudyMemberStatusIn(memberId, studyId, studyMemberStatuses)
.orElseThrow(() -> new GeneralException(ErrorStatus._STUDY_MEMBER_NOT_FOUND));
}

Optional<StudyMember> findByMemberIdAndStudyIdAndStudyMemberStatusNot(Long memberId, Long studyId,
StudyMemberStatus status);
Optional<StudyMember> findByMemberIdAndStudyIdAndStudyMemberStatusIn(Long memberId, Long studyId,
List<StudyMemberStatus> studyMemberStatuses);

Optional<StudyMember> findByMemberIdAndStudyId(Long memberId, Long studyId);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.mockito.Mockito.when;

import java.util.List;
import java.util.Optional;
import kr.spot.exception.GeneralException;
import kr.spot.study.domain.Study;
Expand Down Expand Up @@ -58,8 +59,8 @@ void should_change_status_to_withdrawn_and_decrease_member_count() {

WithdrawStudyRequest request = new WithdrawStudyRequest(WithdrawReason.NO_MORE_NEEDS, null);

when(studyMemberRepository.getByMemberIdAndStudyIdAndStudyMemberStatusNot(memberId, STUDY_ID,
StudyMemberStatus.WITHDRAWN))
when(studyMemberRepository.getByMemberIdAndStudyIdAndStudyMemberStatusIn(memberId, STUDY_ID,
List.of(StudyMemberStatus.APPROVED, StudyMemberStatus.OWNER)))
.thenReturn(regularMember);
when(studyRepository.getStudyById(STUDY_ID)).thenReturn(study);

Expand Down Expand Up @@ -87,9 +88,8 @@ void should_transfer_ownership_and_decrease_member_count() {

WithdrawStudyRequest request = new WithdrawStudyRequest(WithdrawReason.FINISHED, nextOwnerId);

when(studyMemberRepository.getByMemberIdAndStudyIdAndStudyMemberStatusNot(ownerId, STUDY_ID,
StudyMemberStatus.WITHDRAWN))
.thenReturn(ownerMember);
when(studyMemberRepository.getByMemberIdAndStudyIdAndStudyMemberStatusIn(ownerId, STUDY_ID,
List.of(StudyMemberStatus.APPROVED, StudyMemberStatus.OWNER))).thenReturn(ownerMember);
when(studyMemberRepository.findByMemberIdAndStudyId(nextOwnerId, STUDY_ID)).thenReturn(
Optional.of(nextOwner));
when(studyRepository.getStudyById(STUDY_ID)).thenReturn(study);
Expand All @@ -115,9 +115,8 @@ void should_throw_exception_when_owner_withdraws_without_next_owner() {

WithdrawStudyRequest request = new WithdrawStudyRequest(WithdrawReason.FINISHED, null);

when(studyMemberRepository.getByMemberIdAndStudyIdAndStudyMemberStatusNot(ownerId, STUDY_ID,
StudyMemberStatus.WITHDRAWN))
.thenReturn(ownerMember);
when(studyMemberRepository.getByMemberIdAndStudyIdAndStudyMemberStatusIn(ownerId, STUDY_ID,
List.of(StudyMemberStatus.APPROVED, StudyMemberStatus.OWNER))).thenReturn(ownerMember);
when(studyRepository.getStudyById(STUDY_ID)).thenReturn(study);

// when & then
Expand All @@ -139,9 +138,8 @@ void should_throw_exception_when_next_owner_is_from_different_study() {

WithdrawStudyRequest request = new WithdrawStudyRequest(WithdrawReason.FINISHED, nextOwnerId);

when(studyMemberRepository.getByMemberIdAndStudyIdAndStudyMemberStatusNot(ownerId, STUDY_ID,
StudyMemberStatus.WITHDRAWN))
.thenReturn(ownerMember);
when(studyMemberRepository.getByMemberIdAndStudyIdAndStudyMemberStatusIn(ownerId, STUDY_ID,
List.of(StudyMemberStatus.APPROVED, StudyMemberStatus.OWNER))).thenReturn(ownerMember);
when(studyMemberRepository.findByMemberIdAndStudyId(nextOwnerId, STUDY_ID)).thenReturn(
Optional.empty());
when(studyRepository.getStudyById(STUDY_ID)).thenReturn(study);
Expand Down