Anton Smirnov
Feb 8, 2022

--

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.

--

--

Anton Smirnov
Anton Smirnov

Written by Anton Smirnov

I’m a software engineer who specializes in testing and automation. My top languages are Java and Swift. My blog is https://test-engineer.tech/

Responses (1)