Skip to content

Instantly share code, notes, and snippets.

Last active February 2, 2020 19:13
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
class UserDetailsController {
private final UserRepository userRepository;
UserDetailsController(UserRepository userRepository) {
this.userRepository = userRepository;
ResponseEntity<UserDetails> getByUserId(@PathVariable("userId") String userId) {
return userRepository.findById(UserId.of(userId))
.orElseGet(() -> ResponseEntity.notFound().build());
private Function<User, UserDetails> toUserDetails() {
return (user) -> new UserDetails(idOf(user), displayNameOf(user));
private String idOf(User user) {
return user.getId().value();
private String displayNameOf(User user) {
return user.getFirstName() + " " + user.getLastName();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment