I'm building a Content Management System with Pages that contain Blocks. I fetch a page with an id and then fetch blocks that is associated with the same page id. In a blocking fashion, I would do:
Page page = repo.getPageById(47);
page.setBlocks(repo.getBlocksByPageId(47));
When doing this reactive it is a mess of flatMaps
and zipWith
:
Mono<Page> = repo.getPageById(47)
.flatMap(page -> repo.getBlocksByPageId(47).collectList().zipWith(Mono.just(page)))
.flatMap(t -> {
List<Block> blocks = t.getT1();
Page page = t.getT2();
page.setBlocks(blocks);
return Mono.just(page);
});
Can you recommend better ways of accomplishing the same result?