Dev #18
@@ -15,4 +15,6 @@ public interface ExpenseHistoryRepository extends JpaRepository<ExpenseHistoryEn
|
|||||||
|
|
||||||
@Query("select h.expenseId from ExpenseHistoryEntry h")
|
@Query("select h.expenseId from ExpenseHistoryEntry h")
|
||||||
List<Long> findAllExpenseIds();
|
List<Long> findAllExpenseIds();
|
||||||
|
|
||||||
|
void deleteByExpenseListId(Long expenseListId);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -39,6 +39,7 @@ public class ExpenseListService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void deleteById(Long id) {
|
public void deleteById(Long id) {
|
||||||
|
historyService.deleteForList(id);
|
||||||
repository.deleteById(id);
|
repository.deleteById(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -57,6 +57,10 @@ public class HistoryService {
|
|||||||
historyRepository.save(baseEntry(list, expense, actor, HistoryEntryType.DELETED));
|
historyRepository.save(baseEntry(list, expense, actor, HistoryEntryType.DELETED));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void deleteForList(Long listId) {
|
||||||
|
historyRepository.deleteByExpenseListId(listId);
|
||||||
|
}
|
||||||
|
|
||||||
public List<FieldChange> diff(Expense before, Expense after) {
|
public List<FieldChange> diff(Expense before, Expense after) {
|
||||||
List<FieldChange> changes = new ArrayList<>();
|
List<FieldChange> changes = new ArrayList<>();
|
||||||
addIfChanged(changes, "title", before.getTitle(), after.getTitle());
|
addIfChanged(changes, "title", before.getTitle(), after.getTitle());
|
||||||
|
|||||||
@@ -109,6 +109,15 @@ class ExpenseListServiceTest {
|
|||||||
assertThat(beforeCaptor.getValue().getAmount()).isEqualTo(12.0);
|
assertThat(beforeCaptor.getValue().getAmount()).isEqualTo(12.0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void deleteById_deletesHistoryEntriesBeforeDeletingList() {
|
||||||
|
service.deleteById(10L);
|
||||||
|
|
||||||
|
org.mockito.InOrder inOrder = org.mockito.Mockito.inOrder(historyService, repository);
|
||||||
|
inOrder.verify(historyService).deleteForList(10L);
|
||||||
|
inOrder.verify(repository).deleteById(10L);
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void deleteExpenseFromList_recordsDeleted() {
|
void deleteExpenseFromList_recordsDeleted() {
|
||||||
AppUser actor = new AppUser(); actor.setId(1L);
|
AppUser actor = new AppUser(); actor.setId(1L);
|
||||||
|
|||||||
Reference in New Issue
Block a user