What I want to do is, updating a customer if it is present but if there is no customer then throw an exception. But I could not find the correct stream function to do that. How can I achieve this ?
public Customer update(Customer customer) throws Exception {
Optional<Customer> customerToUpdate = customerRepository.findById(customer.getId());
customerToUpdate.ifPresentOrElse(value -> return customerRepository.save(customer),
throw new Exception("customer not found"));
}
I could not return the value coming from save function because it is saying that it is void method and not expecting return value.