chore: read from multiple collections async

parent d59f426e
......@@ -101,6 +101,15 @@ public class OrderController {
}
@GetMapping("/get/async/{id}")
public Mono<OrderDto> readAsyncOrderEvent(@PathVariable String id) throws InterruptedException {
log.info("Order id Received for retrieval : {}",id);
return orderProcessingService.readAsync(id);
}
}
......@@ -202,4 +202,34 @@ public class OrderProcessingService {
}
public Mono<OrderDto> readAsync(String id ) {
return reactiveOps.findById(id,Order.class)
.map(order -> OrderMapper.INSTANCE.orderEntityToDto(order))
.log("Awaiting to fetch all order information")
.doOnNext(orderDto -> {
reactiveOps.findById(id,ShippingAddress.class)
.toFuture().whenCompleteAsync((shippingAddress, throwable1) -> {
orderDto.setShippingAddress(OrderMapper.INSTANCE.shippingAddressEntityToDTO(shippingAddress));
}).join();
reactiveOps.findById(id,BuyerInfo.class)
.toFuture().whenCompleteAsync((buyerInfo, throwable2) -> {
orderDto.setBuyerInfo(OrderMapper.INSTANCE.buyerInfoEntityToDto(buyerInfo));
}).join();
reactiveOps.findById(id,BuyerTaxInfo.class)
.toFuture().whenCompleteAsync((buyerTaxInfo, throwable3) -> {
orderDto.getBuyerInfo().setBuyerTaxInfo(OrderMapper.INSTANCE.buyerTaxInfoEntityToDto(buyerTaxInfo));
}).join();
}).doOnSuccess(orderDto -> log.info("Final Order Information : {}",orderDto));
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment