Implementation of controller annotations

The following is UserController, which enables reset password for User and the listing of users in the User Registration module:

@RestController
@RequestMapping("/users")
public class UserController {

private final AsyncService asyncService;
private final UserService userService;

public UserController(AsyncService asyncService, UserService userService) {
this.asyncService = asyncService;
this.userService = userService;
}

@GetMapping
public List<String> listUsers() {
return userService.getAll().stream().map(u -> u.getEmail()).collect(Collectors.toList());
}

@RequestMapping("/reset-password/{email}")
@ResponseStatus(HttpStatus.OK)
public void resetPassword(@PathVariable("email") String email) throws Exception {
asyncService.sendResetPassword(email);
}

}

The preceding controller is mapped to the URL "/users" and injects AsyncService and UserService. The listUsers method is mapped to the GET request, which will call the UserService.getAll() method to return all the users and then use the Stream API to list the email addresses of users returned.

The resetPassword method is mapped to the URL "/users/reset-password/{email}" with the GET request, which will call the AsyncService.sendResetPassword method with the passed in an email address. 

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.22.74.232