Skip to content

Commit

Permalink
refactor: 골룸 시작, 나가기 쿼리 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
miseongk committed May 14, 2024
1 parent a18c81a commit 731c8a4
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -135,13 +135,13 @@ private GoalRoom findGoalRoomById(final Long goalRoomId) {

private void validateJoinGoalRoom(final GoalRoom goalRoom, final Member member) {
final GoalRoomPendingMembers goalRoomPendingMembers = new GoalRoomPendingMembers(
findGoalRoomPendingMembers(goalRoom));
findGoalRoomPendingMembersWithPessimisticLock(goalRoom));
validateMemberCount(goalRoomPendingMembers, goalRoom);
validateRecruiting(goalRoom);
validateAlreadyParticipated(goalRoomPendingMembers, member);
}

private List<GoalRoomPendingMember> findGoalRoomPendingMembers(final GoalRoom goalRoom) {
private List<GoalRoomPendingMember> findGoalRoomPendingMembersWithPessimisticLock(final GoalRoom goalRoom) {
return goalRoomPendingMemberRepository.findByGoalRoomIdWithPessimisticLock(goalRoom.getId());
}

Expand Down Expand Up @@ -193,6 +193,10 @@ private void leaveRecruitingGoalRoom(final Member member, final GoalRoom goalRoo
goalRoomPendingMemberRepository.delete(goalRoomPendingMember);
}

private List<GoalRoomPendingMember> findGoalRoomPendingMembers(final GoalRoom goalRoom) {
return goalRoomPendingMemberRepository.findByGoalRoom(goalRoom);
}

private void leaveCompletedGoalRoom(final Member member, final GoalRoom goalRoom) {
final GoalRoomMembers goalRoomMembers = new GoalRoomMembers(findGoalRoomMembers(goalRoom));
final GoalRoomMember goalRoomMember = goalRoomMembers.findByMemberId(member.getId())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -230,9 +230,9 @@ static void setUp() {

when(memberRepository.findByIdentifier(any()))
.thenReturn(Optional.of(follower));
when(goalRoomRepository.findGoalRoomByIdWithPessimisticLock(anyLong()))
when(goalRoomRepository.findById(anyLong()))
.thenReturn(Optional.of(goalRoom));
when(goalRoomPendingMemberRepository.findByGoalRoom(any()))
when(goalRoomPendingMemberRepository.findByGoalRoomIdWithPessimisticLock(any()))
.thenReturn(List.of(new GoalRoomPendingMember(GoalRoomRole.LEADER, goalRoom, creator.getId())));
when(goalRoomPendingMemberRepository.save(any()))
.thenReturn(new GoalRoomPendingMember(GoalRoomRole.FOLLOWER, goalRoom, follower.getId()));
Expand Down Expand Up @@ -261,7 +261,7 @@ static void setUp() {

when(memberRepository.findByIdentifier(any()))
.thenReturn(Optional.of(follower));
when(goalRoomRepository.findGoalRoomByIdWithPessimisticLock(anyLong()))
when(goalRoomRepository.findById(anyLong()))
.thenReturn(Optional.empty());

//when, then
Expand All @@ -283,9 +283,9 @@ static void setUp() {

when(memberRepository.findByIdentifier(any()))
.thenReturn(Optional.of(follower));
when(goalRoomRepository.findGoalRoomByIdWithPessimisticLock(anyLong()))
when(goalRoomRepository.findById(anyLong()))
.thenReturn(Optional.of(goalRoom));
when(goalRoomPendingMemberRepository.findByGoalRoom(any()))
when(goalRoomPendingMemberRepository.findByGoalRoomIdWithPessimisticLock(any()))
.thenReturn(List.of(new GoalRoomPendingMember(GoalRoomRole.LEADER, goalRoom, creator.getId())));

//when, then
Expand All @@ -307,9 +307,9 @@ static void setUp() {

when(memberRepository.findByIdentifier(any()))
.thenReturn(Optional.of(follower));
when(goalRoomRepository.findGoalRoomByIdWithPessimisticLock(anyLong()))
when(goalRoomRepository.findById(anyLong()))
.thenReturn(Optional.of(goalRoom));
when(goalRoomPendingMemberRepository.findByGoalRoom(any()))
when(goalRoomPendingMemberRepository.findByGoalRoomIdWithPessimisticLock(any()))
.thenReturn(List.of(new GoalRoomPendingMember(GoalRoomRole.LEADER, goalRoom, creator.getId())));

//when, then
Expand All @@ -329,9 +329,9 @@ static void setUp() {

when(memberRepository.findByIdentifier(any()))
.thenReturn(Optional.of(creator));
when(goalRoomRepository.findGoalRoomByIdWithPessimisticLock(anyLong()))
when(goalRoomRepository.findById(anyLong()))
.thenReturn(Optional.of(goalRoom));
when(goalRoomPendingMemberRepository.findByGoalRoom(any()))
when(goalRoomPendingMemberRepository.findByGoalRoomIdWithPessimisticLock(any()))
.thenReturn(List.of(new GoalRoomPendingMember(GoalRoomRole.LEADER, goalRoom, creator.getId())));

//when, then
Expand Down

0 comments on commit 731c8a4

Please sign in to comment.