Created
April 24, 2020 17:33
-
-
Save digimon1740/9920d2794450c348d25e48e404bd36fd to your computer and use it in GitHub Desktop.
using ResponseEntity on Spring WebFlux
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
@RestController | |
public class UserController { | |
private UserService userService; | |
public UserController(UserService userService) { | |
this.userService = userService; | |
} | |
@GetMapping("/users/{userId}") | |
public Mono<ResponseEntity<User>> get(@PathVariable Long userId) { | |
Mono<User> userMono = userService.getById(userId); | |
return userMono.map((user) -> { | |
if (user.isAdult()) { | |
return ResponseEntity.ok().header("X-User-Adult", "true").build(); | |
} | |
return ResponseEntity.status(HttpStatus.FORBIDDEN).build(); | |
}); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment