diff --git a/server/src/main/java/server/haengdong/application/BillActionService.java b/server/src/main/java/server/haengdong/application/BillActionService.java index 9c730db5d..203bc39be 100644 --- a/server/src/main/java/server/haengdong/application/BillActionService.java +++ b/server/src/main/java/server/haengdong/application/BillActionService.java @@ -86,6 +86,7 @@ public void deleteBillAction(String token, Long actionId) { Event event = eventRepository.findByToken(token) .orElseThrow(() -> new HaengdongException(HaengdongErrorCode.EVENT_NOT_FOUND)); + billActionDetailRepository.deleteByBillAction_Action_EventAndBillAction_ActionId(event, actionId); billActionRepository.deleteByAction_EventAndActionId(event, actionId); } } diff --git a/server/src/main/java/server/haengdong/domain/action/BillActionDetailRepository.java b/server/src/main/java/server/haengdong/domain/action/BillActionDetailRepository.java index eb910eabf..7197b54bf 100644 --- a/server/src/main/java/server/haengdong/domain/action/BillActionDetailRepository.java +++ b/server/src/main/java/server/haengdong/domain/action/BillActionDetailRepository.java @@ -2,7 +2,10 @@ import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.stereotype.Repository; +import server.haengdong.domain.event.Event; @Repository public interface BillActionDetailRepository extends JpaRepository { + + void deleteByBillAction_Action_EventAndBillAction_ActionId(Event event, Long actionId); } diff --git a/server/src/test/java/server/haengdong/application/BillActionServiceTest.java b/server/src/test/java/server/haengdong/application/BillActionServiceTest.java index 6b71d37bd..48f24a6fb 100644 --- a/server/src/test/java/server/haengdong/application/BillActionServiceTest.java +++ b/server/src/test/java/server/haengdong/application/BillActionServiceTest.java @@ -46,6 +46,11 @@ class BillActionServiceTest extends ServiceTestSupport { void saveAllBillAction() { Event event = Fixture.EVENT1; Event savedEvent = eventRepository.save(event); + Action action1 = new Action(event, 1L); + Action action2 = new Action(event, 2L); + MemberAction memberAction1 = new MemberAction(action1, "백호", MemberActionStatus.IN, 1L); + MemberAction memberAction2 = new MemberAction(action2, "망쵸", MemberActionStatus.IN, 2L); + memberActionRepository.saveAll(List.of(memberAction1, memberAction2)); List requests = List.of( new BillActionAppRequest("뽕족", 10_000L), @@ -58,8 +63,8 @@ void saveAllBillAction() { assertThat(actions).extracting(BillAction::getTitle, BillAction::getPrice, BillAction::getSequence) .containsExactlyInAnyOrder( - tuple("뽕족", 10_000L, 1L), - tuple("인생맥주", 15_000L, 2L) + tuple("뽕족", 10_000L, 3L), + tuple("인생맥주", 15_000L, 4L) ); } @@ -163,6 +168,26 @@ void deleteBillAction() { assertThat(billActionRepository.findById(billAction.getId())).isEmpty(); } + @DisplayName("지출 내역을 삭제하면 지출 상세도 삭제된다.") + @Test + void deleteBillActionTest1() { + Event event = Fixture.EVENT1; + eventRepository.save(event); + MemberAction memberAction1 = new MemberAction(new Action(event, 1L), "백호", MemberActionStatus.IN, 1L); + MemberAction memberAction2 = new MemberAction(new Action(event, 2L), "망쵸", MemberActionStatus.IN, 2L); + BillAction billAction = new BillAction(new Action(event, 3L), "커피", 50_900L); + BillActionDetail billActionDetail1 = new BillActionDetail(billAction, "백호", 25_450L); + BillActionDetail billActionDetail2 = new BillActionDetail(billAction, "망쵸", 25_450L); + memberActionRepository.saveAll(List.of(memberAction1, memberAction2)); + billActionRepository.save(billAction); + billActionDetailRepository.saveAll(List.of(billActionDetail1, billActionDetail2)); + Long actionId = billAction.getAction().getId(); + + billActionService.deleteBillAction(event.getToken(), actionId); + + assertThat(billActionDetailRepository.findAll()).isEmpty(); + } + @DisplayName("지출 내역 삭제 시 행사가 존재하지 않으면 예외가 발생한다.") @Test void deleteBillAction1() {