From 591df0d4dff2623d57ab4fd6f321414a9c477908 Mon Sep 17 00:00:00 2001 From: Geonwoo Lee <82176176+geonwoo0215@users.noreply.github.com> Date: Fri, 7 Apr 2023 00:54:04 +0900 Subject: [PATCH] =?UTF-8?q?refactor(crewMember):=20=EC=82=AD=EC=A0=9C=20?= =?UTF-8?q?=EC=BF=BC=EB=A6=AC=20=EB=B3=80=EA=B2=BD=20-=20Hard=20delete?= =?UTF-8?q?=EB=A1=9C=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../repository/CrewMemberRepository.java | 5 +++- .../repository/CrewMemberRepositoryTest.java | 5 ++-- .../service/CrewMemberServiceImplTest.java | 25 +++---------------- 3 files changed, 9 insertions(+), 26 deletions(-) diff --git a/src/main/java/com/prgrms/mukvengers/domain/crewmember/repository/CrewMemberRepository.java b/src/main/java/com/prgrms/mukvengers/domain/crewmember/repository/CrewMemberRepository.java index 7347cefe..e5da6449 100644 --- a/src/main/java/com/prgrms/mukvengers/domain/crewmember/repository/CrewMemberRepository.java +++ b/src/main/java/com/prgrms/mukvengers/domain/crewmember/repository/CrewMemberRepository.java @@ -4,6 +4,7 @@ import java.util.Optional; import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.Modifying; import org.springframework.data.jpa.repository.Query; import org.springframework.data.repository.query.Param; @@ -36,6 +37,8 @@ SELECT COUNT(cm) """) List findAllByCrewId(@Param(value = "crewId") Long crewId); - void deleteByUserIdAndCrewId(@Param(value = "userId") Long userId, @Param(value = "crewId") Long crewId); + @Modifying + @Query(value = "DELETE FROM crew_member cm WHERE user_id = :userId AND crew_id = :crewId", nativeQuery = true) + int deleteByUserIdAndCrewId(@Param(value = "userId") Long userId, @Param(value = "crewId") Long crewId); } diff --git a/src/test/java/com/prgrms/mukvengers/domain/crewmember/repository/CrewMemberRepositoryTest.java b/src/test/java/com/prgrms/mukvengers/domain/crewmember/repository/CrewMemberRepositoryTest.java index 518dcc8f..50c940af 100644 --- a/src/test/java/com/prgrms/mukvengers/domain/crewmember/repository/CrewMemberRepositoryTest.java +++ b/src/test/java/com/prgrms/mukvengers/domain/crewmember/repository/CrewMemberRepositoryTest.java @@ -94,11 +94,10 @@ void deleteByUserId_success() { crewMemberRepository.save(crewMember); //when - crewMemberRepository.deleteByUserIdAndCrewId(savedUser1Id, crew.getId()); + int delete = crewMemberRepository.deleteByUserIdAndCrewId(savedUser1Id, crew.getId()); //then - Optional optionalCrewMember = crewMemberRepository.findById(crewMember.getId()); - assertThat(optionalCrewMember).isEmpty(); + assertThat(delete).isEqualTo(1); } } \ No newline at end of file diff --git a/src/test/java/com/prgrms/mukvengers/domain/crewmember/service/CrewMemberServiceImplTest.java b/src/test/java/com/prgrms/mukvengers/domain/crewmember/service/CrewMemberServiceImplTest.java index 1d8463f6..cac47dc7 100644 --- a/src/test/java/com/prgrms/mukvengers/domain/crewmember/service/CrewMemberServiceImplTest.java +++ b/src/test/java/com/prgrms/mukvengers/domain/crewmember/service/CrewMemberServiceImplTest.java @@ -18,7 +18,6 @@ import com.prgrms.mukvengers.domain.crewmember.model.CrewMember; import com.prgrms.mukvengers.domain.crewmember.repository.CrewMemberRepository; import com.prgrms.mukvengers.global.common.dto.IdResponse; -import com.prgrms.mukvengers.utils.CrewMemberObjectProvider; class CrewMemberServiceImplTest extends ServiceTest { @@ -51,7 +50,7 @@ void create_success() { .hasFieldOrPropertyWithValue("crew", crew) .hasFieldOrPropertyWithValue("crewMemberRole", LEADER); } - + @Test @DisplayName("[성공] 사용자 아이디, 강퇴할 사용자 아이디, 모임 아이디로 사용자를 강퇴한다.") void block_success() { @@ -60,7 +59,7 @@ void block_success() { Crew crew = createCrew(savedStore); crewRepository.save(crew); - CrewMember leader = createCrewMember(savedUser1Id, crew, LEADER); + CrewMember leader = createCrewMember(savedUser1Id, crew, LEADER); CrewMember member = createCrewMember(savedUser2Id, crew, MEMBER); crewMemberRepository.save(leader); @@ -109,24 +108,6 @@ void block_fail_NotMember() { assertThatThrownBy( () -> crewMemberService.block(leader.getUserId(), leader.getUserId(), crew.getId())).isInstanceOf( NotMemberException.class); - } - - @Test - @DisplayName("[성공] 모임원 아이디로 모임원을 삭제한다") - void delete_success() { - - //given - Crew crew = createCrew(savedStore); - crewRepository.save(crew); - - CrewMember crewMember = CrewMemberObjectProvider.createCrewMember(savedUser1Id, crew, MEMBER); - crewMemberRepository.save(crewMember); - - //when - crewMemberService.delete(crewMember.getUserId(), crew.getId()); - - //then - Optional optionalCrewMember = crewMemberRepository.findById(crewMember.getId()); - assertThat(optionalCrewMember).isEmpty(); } + } \ No newline at end of file