To make it separate from our existing functional-based programming, we have created a new controller that will expose some of the methods in a RESTful way, using the newly created ReactiveMovieRepository:
@RestController
public class MovieController {
@Autowired
private ReactiveMovieRepository reactiveMovieRepository;
@GetMapping("/movies")
public Flux<Movie> getAllMovies() {
return reactiveMovieRepository.findAll();
}
@GetMapping("/movies/{genre}")
public Flux<Movie> getAllMoviesByGenre(@PathVariable String genre) {
return reactiveMovieRepository.findByGenre(genre);
}
@GetMapping("/movies/{title}/{genre}")
public Flux<Movie> getAllMoviesByTitleAndGenre
(@PathVariable String title, @PathVariable String genre) {
return reactiveMovieRepository.findByTitleAndGenre(title, genre);
}
@PostMapping("/movies")
public Mono<Movie> createMovies(@Valid @RequestBody Movie movie) {
return reactiveMovieRepository.save(movie);
}
}
The class is quite straightforward; each method has appropriate mapping and uses corresponding repository classes to actually do the job.