Last active
March 24, 2021 10:08
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Service | |
public class UserService { | |
@Autowired | |
UserRepository userRepository; | |
@Autowired | |
ModelMapper modelMapper; | |
public void saveUser(UserDto userDto) { | |
Optional<User> optionalUser = userRepository.findByEmail(userDto.getEmail()); | |
if (!optionalUser.isPresent()) { | |
// insert new user | |
User user = modelMapper.map(userDto, User.class); | |
userRepository.save(user); | |
} | |
} | |
public User getUser(String email) { | |
Optional<User> optionalUser = userRepository.findByEmail(email); | |
if (optionalUser.isPresent()) { | |
return optionalUser.get(); | |
} | |
return null; | |
} | |
public List<User> getAllUsers() { | |
return userRepository.findAll(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment