Repository

We will be using hardcoded movies as our data structure for this sample and will write methods in a reactive way, to expose methods in our repository class. These methods can be used to manipulate the data structure of the movies. Our repository class is a conventional one, but the right data structures, in the form of Mono and Flux, aid in bringing a reactive nature to the application:

@Repository
public class MovieRepositoryImpl implements MovieRepository {
private Map<Long, Movie> movies = new HashMap<Long, Movie>();

@PostConstruct
public void initIt() throws Exception {
movies.put(Long.valueOf(1), new Movie(Long.valueOf(1), "Moonlight",
"Drama"));
movies.put(Long.valueOf(2), new Movie(Long.valueOf(2), "Dunkirk",
"Drama/Thriller"));
movies.put(Long.valueOf(3), new Movie(Long.valueOf(3), "Get Out",
"Mystery/Thriller"));
movies.put(Long.valueOf(4), new Movie(Long.valueOf(4), "The Shape of
Water", "Drama/Thriller"));
}
@Override
public Mono<Movie> getMovieById(Long id) {
return Mono.just(movies.get(id));
}
//...Other methods
}

The class is just a snippet extracted from the class, and shows only one method (getMovieById). As always, our class implements an interface (MovieRepository), and this reference will be used in other parts of the application (using Spring's Dependency Injection capability).

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

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