Last active
January 11, 2018 10:14
-
-
Save Sam-Kruglov/cb3c20371e9a277bae215c81953a1e74 to your computer and use it in GitHub Desktop.
DTO Alter "getUsername" to have links
This file contains hidden or 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
@RepositoryRestController | |
public class UserController { | |
private final RepositoryEntityLinks links; | |
private final UserRepository userRepository; | |
// all arg constructor | |
@GetMapping("users/search/username") | |
public ResponseEntity<Resource<UserUsername>> addLinksToUserUsername(@RequestParam("id") Long id){ | |
Resource<UserUsername> usernameResource = new Resource<>(userRepository.findUsernameById(id)); | |
usernameResource.add(links.linkToSearchResource(User.class, "getUsername").withSelfRel()); | |
usernameResource.add(links.linkToSingleResource(User.class, id)); | |
return ResponseEntity.ok(usernameResource); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment