@Test(expected = NotFoundException.class) public void shouldFailToDeleteACounterThatDoesNotExist() throws NotFoundException { User user = new User(); counterDAO.delete(user, PROJECT_ID, Collections.singletonList(-1L)); }
public void delete(User user, Long projectId, List<Long> counterIds) throws NotFoundException { final Project project = projectRepository.findById(projectId).orElse(null); final List<Counter> counters = counterRepository.findAllByIdIn(counterIds); if (counters.size() != counterIds.size()) { throw new NotFoundException("At least one counter cannot be found"); } for (Counter counter : counters) { checkAccess(user, project, counter); } counterRepository.deleteAll(counters); }
CounterDAO { public void delete(User user, Long projectId, List<Long> counterIds) throws NotFoundException { final Project project = projectRepository.findById(projectId).orElse(null); final List<Counter> counters = counterRepository.findAllByIdIn(counterIds); if (counters.size() != counterIds.size()) { throw new NotFoundException("At least one counter cannot be found"); } for (Counter counter : counters) { checkAccess(user, project, counter); } counterRepository.deleteAll(counters); } }
CounterDAO { public void delete(User user, Long projectId, List<Long> counterIds) throws NotFoundException { final Project project = projectRepository.findById(projectId).orElse(null); final List<Counter> counters = counterRepository.findAllByIdIn(counterIds); if (counters.size() != counterIds.size()) { throw new NotFoundException("At least one counter cannot be found"); } for (Counter counter : counters) { checkAccess(user, project, counter); } counterRepository.deleteAll(counters); } @Autowired  CounterDAO(ProjectDAO projectDAO,
                      CounterRepository counterRepository,
                      ProjectRepository projectRepository); }
CounterDAO { public void delete(User user, Long projectId, List<Long> counterIds) throws NotFoundException { final Project project = projectRepository.findById(projectId).orElse(null); final List<Counter> counters = counterRepository.findAllByIdIn(counterIds); if (counters.size() != counterIds.size()) { throw new NotFoundException("At least one counter cannot be found"); } for (Counter counter : counters) { checkAccess(user, project, counter); } counterRepository.deleteAll(counters); } @Autowired  CounterDAO(ProjectDAO projectDAO,
                      CounterRepository counterRepository,
                      ProjectRepository projectRepository); void create(User user, Counter counter); List<Counter> getAll(User user, Long projectId); Counter update(User user, Counter counter); void delete(User user, Long projectId, List<Long> counterIds); void checkAccess(User user, Project project, Counter counter); }
CounterDAO { public void delete(User user, Long projectId, List<Long> counterIds) throws NotFoundException { final Project project = projectRepository.findById(projectId).orElse(null); final List<Counter> counters = counterRepository.findAllByIdIn(counterIds); if (counters.size() != counterIds.size()) { throw new NotFoundException("At least one counter cannot be found"); } for (Counter counter : counters) { checkAccess(user, project, counter); } counterRepository.deleteAll(counters); } @Autowired  CounterDAO(ProjectDAO projectDAO,
                      CounterRepository counterRepository,
                      ProjectRepository projectRepository); void create(User user, Counter counter); List<Counter> getAll(User user, Long projectId); Counter update(User user, Counter counter); void delete(User user, Long projectId, List<Long> counterIds); void checkAccess(User user, Project project, Counter counter);  }