Good day. I hope you are well.
This is a very interesting article. I liked your description and approach.
My apologies, but I have a few comments for you.
I think, you need to check firstname and lastname before saving :
public User createUser(User user) { return userRepository.save(user); }
For example what happenes if a user with firstname and lastname will exist in the database?
Before delete you need to check id or you need use try catch:
public String deleteUserById(int id) { userRepository.deleteById(id); return "User "+ id +" deleted"; }
Bad practices return only null:
return userRepository.findById(id).orElse(null);
You need to return some informative message.
E.g: return userRepository.findById(id).or Else Throw(() -> new NoSuchElementException("id not found"));
And this method too:
public User updateUserById(User user) {}
I hope my comments will be very helpful for you.