@Test(expected = CustomGoalNotSavedException.class) public void saveDuplicatedBulkSaveCustomGoalDtoTest() { CustomGoalSaveRequestDto customGoalDtoToSave = new CustomGoalSaveRequestDto("foo"); CustomGoal customGoal = new CustomGoal(1L, customGoalDtoToSave.getText(), null, null); user.setCustomGoals(Collections.singletonList(customGoal)); when(modelMapper.map(customGoalDtoToSave, CustomGoal.class)).thenReturn(customGoal); customGoalService.save( new BulkSaveCustomGoalDto(Collections.singletonList(customGoalDtoToSave)), user ); }
@Transactional @Override public List<CustomGoalResponseDto> save(BulkSaveCustomGoalDto bulkSave, User user) { List<CustomGoalSaveRequestDto> dto = bulkSave.getCustomGoalSaveRequestDtoList(); List<String> errorMessages = findDuplicates(dto, user); if (!errorMessages.isEmpty()) { throw new CustomGoalNotSavedException(CUSTOM_GOAL_WHERE_NOT_SAVED + errorMessages.toString()); } customGoalRepo.saveAll(user.getCustomGoals()); return user.getCustomGoals().stream() .map(customGoal -> modelMapper.map(customGoal, CustomGoalResponseDto.class)) .collect(Collectors.toList()); }
CustomGoalServiceImpl implements CustomGoalService { @Transactional @Override public List<CustomGoalResponseDto> save(BulkSaveCustomGoalDto bulkSave, User user) { List<CustomGoalSaveRequestDto> dto = bulkSave.getCustomGoalSaveRequestDtoList(); List<String> errorMessages = findDuplicates(dto, user); if (!errorMessages.isEmpty()) { throw new CustomGoalNotSavedException(CUSTOM_GOAL_WHERE_NOT_SAVED + errorMessages.toString()); } customGoalRepo.saveAll(user.getCustomGoals()); return user.getCustomGoals().stream() .map(customGoal -> modelMapper.map(customGoal, CustomGoalResponseDto.class)) .collect(Collectors.toList()); } }
CustomGoalServiceImpl implements CustomGoalService { @Transactional @Override public List<CustomGoalResponseDto> save(BulkSaveCustomGoalDto bulkSave, User user) { List<CustomGoalSaveRequestDto> dto = bulkSave.getCustomGoalSaveRequestDtoList(); List<String> errorMessages = findDuplicates(dto, user); if (!errorMessages.isEmpty()) { throw new CustomGoalNotSavedException(CUSTOM_GOAL_WHERE_NOT_SAVED + errorMessages.toString()); } customGoalRepo.saveAll(user.getCustomGoals()); return user.getCustomGoals().stream() .map(customGoal -> modelMapper.map(customGoal, CustomGoalResponseDto.class)) .collect(Collectors.toList()); }  }
CustomGoalServiceImpl implements CustomGoalService { @Transactional @Override public List<CustomGoalResponseDto> save(BulkSaveCustomGoalDto bulkSave, User user) { List<CustomGoalSaveRequestDto> dto = bulkSave.getCustomGoalSaveRequestDtoList(); List<String> errorMessages = findDuplicates(dto, user); if (!errorMessages.isEmpty()) { throw new CustomGoalNotSavedException(CUSTOM_GOAL_WHERE_NOT_SAVED + errorMessages.toString()); } customGoalRepo.saveAll(user.getCustomGoals()); return user.getCustomGoals().stream() .map(customGoal -> modelMapper.map(customGoal, CustomGoalResponseDto.class)) .collect(Collectors.toList()); }  @Transactional @Override List<CustomGoalResponseDto> save(BulkSaveCustomGoalDto bulkSave, User user); @Transactional @Override List<CustomGoalResponseDto> findAll(); @Transactional @Override CustomGoalResponseDto findById(Long id); @Transactional @Override List<CustomGoalResponseDto> updateBulk(BulkCustomGoalDto bulkCustomGoalDto); @Transactional @Override List<CustomGoalResponseDto> findAllByUser(Long userId); @Transactional @Override List<Long> bulkDelete(String ids); }
CustomGoalServiceImpl implements CustomGoalService { @Transactional @Override public List<CustomGoalResponseDto> save(BulkSaveCustomGoalDto bulkSave, User user) { List<CustomGoalSaveRequestDto> dto = bulkSave.getCustomGoalSaveRequestDtoList(); List<String> errorMessages = findDuplicates(dto, user); if (!errorMessages.isEmpty()) { throw new CustomGoalNotSavedException(CUSTOM_GOAL_WHERE_NOT_SAVED + errorMessages.toString()); } customGoalRepo.saveAll(user.getCustomGoals()); return user.getCustomGoals().stream() .map(customGoal -> modelMapper.map(customGoal, CustomGoalResponseDto.class)) .collect(Collectors.toList()); }  @Transactional @Override List<CustomGoalResponseDto> save(BulkSaveCustomGoalDto bulkSave, User user); @Transactional @Override List<CustomGoalResponseDto> findAll(); @Transactional @Override CustomGoalResponseDto findById(Long id); @Transactional @Override List<CustomGoalResponseDto> updateBulk(BulkCustomGoalDto bulkCustomGoalDto); @Transactional @Override List<CustomGoalResponseDto> findAllByUser(Long userId); @Transactional @Override List<Long> bulkDelete(String ids);  }