@RestController @RequestMapping(value="/api") public class UserResource extends Object
This class accesses the User entity, and needs to fetch its collection of authorities.
For a normal use-case, it would be better to have an eager relationship between User and Authority, and send everything to the client side: there would be no View Model and DTO, a lot less code, and an outer-join which would be good for performance.
We use a View Model and a DTO for 3 reasons:
Another option would be to have a specific JPA entity graph to handle this case.
| Constructor and Description |
|---|
UserResource(UserRepository userRepository,
UserService userService) |
| Modifier and Type | Method and Description |
|---|---|
org.springframework.http.ResponseEntity<UserDTO> |
createUser(ManagedUserVM managedUserVM)
POST /users : Creates a new user.
|
org.springframework.http.ResponseEntity<Void> |
deleteUser(String login)
DELETE /users/:login : delete the "login" User.
|
org.springframework.http.ResponseEntity<List<UserDTO>> |
getAllUsers(org.springframework.data.domain.Pageable pageable)
GET /users : get all users.
|
org.springframework.http.ResponseEntity<UserDTO> |
getUser(String login)
GET /users/:login : get the "login" user.
|
org.springframework.http.ResponseEntity<UserDTO> |
updateUser(ManagedUserVM managedUserVM)
PUT /users : Updates an existing User.
|
public UserResource(UserRepository userRepository, UserService userService)
@PostMapping(value="/users") @Timed @Secured(value="ROLE_ADMIN") public org.springframework.http.ResponseEntity<UserDTO> createUser(@RequestBody ManagedUserVM managedUserVM) throws URISyntaxException
Creates a new user if the login and email are not already used, and sends an mail with an activation link. The user needs to be activated on creation.
managedUserVM - the user to createURISyntaxException - if the Location URI syntax is incorrect@PutMapping(value="/users") @Timed @Secured(value="ROLE_ADMIN") public org.springframework.http.ResponseEntity<UserDTO> updateUser(@RequestBody ManagedUserVM managedUserVM)
managedUserVM - the user to update@GetMapping(value="/users") @Timed public org.springframework.http.ResponseEntity<List<UserDTO>> getAllUsers(org.springframework.data.domain.Pageable pageable) throws URISyntaxException
pageable - the pagination informationURISyntaxException - if the pagination headers couldn't be generated@GetMapping(value="/users/{login:^[_\'.@A-Za-z0-9-]*$}")
@Timed
public org.springframework.http.ResponseEntity<UserDTO> getUser(@PathVariable
String login)
login - the login of the user to find@DeleteMapping(value="/users/{login:^[_\'.@A-Za-z0-9-]*$}")
@Timed
@Secured(value="ROLE_ADMIN")
public org.springframework.http.ResponseEntity<Void> deleteUser(@PathVariable
String login)
login - the login of the user to deleteCopyright © 2019 Power TAC. All rights reserved.