Created
September 30, 2019 06:35
-
-
Save Aleksandr-Filichkin/fe700a82180cde91e652eb9ee2b9d0c0 to your computer and use it in GitHub Desktop.
Reactive controller
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 | |
@RequestMapping("/reactive") | |
public class Controller { | |
private final R2DBCSubscriptionRepository userRepository; | |
@Autowired | |
public Controller(R2DBCSubscriptionRepository userRepository) { | |
this.userRepository = userRepository; | |
} | |
@GetMapping("user/{id}") | |
public Mono<User> get(@PathVariable long id) { | |
return userRepository.findById(id); | |
} | |
@PostMapping("user") | |
public Mono<User> add(@RequestBody User user) { | |
user.setCreated(Instant.now()); | |
return userRepository.save(user); | |
} | |
@DeleteMapping("user/{id}") | |
public Mono<Void> delete(@PathVariable long id) { | |
return userRepository.deleteById(id); | |
} | |
@GetMapping("users") | |
public Flux<User> getWithLimit(@RequestParam int limit) { | |
return userRepository.findWithLimit(limit); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment