Skip to content

Commit

Permalink
feat: 지출 내역 삭제 시, 상세 내역 삭제 로직 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
3Juhwan committed Aug 16, 2024
1 parent 67f8a08 commit 0298a1a
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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<BillActionDetail, Long> {

void deleteByBillAction_Action_EventAndBillAction_ActionId(Event event, Long actionId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -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<BillActionAppRequest> requests = List.of(
new BillActionAppRequest("뽕족", 10_000L),
Expand All @@ -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)
);
}

Expand Down Expand Up @@ -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() {
Expand Down

0 comments on commit 0298a1a

Please sign in to comment.