Created
August 27, 2022 09:45
-
-
Save susimsek/c5efa0b3984558106741904ded37d953 to your computer and use it in GitHub Desktop.
Graphql Review Microservice
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
@Controller | |
class ReviewController( | |
private val reviewService: ReviewService | |
) { | |
@BatchMapping | |
fun reviews(products: MutableList<Product>): Mono<Map<Product, List<Review>>> { | |
val productIds = products.map {it.id}.toMutableList() | |
val result = reviewService.getReviewsByProductIdsIn(productIds) | |
return result | |
.collectMultimap { it.productId } | |
.map { m -> | |
productIds.associate { id -> | |
val key = products.find { id.equals(it.id) }!! | |
val value = m[id]?.toMutableList() ?: emptyList() | |
key to value | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment