If I couldn't find a user in my db with given id. I want to return an exception instead of null Dto, how can I do this?
public UserDto updateUser(Long id, UserDto userDto) {
UserDto userDtoNew = null;
if (userRepository.findById(id).isPresent()) {
User existingUser = userRepository.findById(id).get();
existingUser.setPassword(userDto.getPassword());
existingUser.setUserName(userDto.getUserName());
userDtoNew = userMapper.toDto(existingUser);
return userDtoNew;
}
return userDtoNew;
}