Following is the function written in a service.
public Mono<BrandRest> createBrand(CreateBrandRequest request) {
record BrandCategoryRest(Brand brandRest, List<CategoryRest> categoryRests){}
return Flux.fromIterable(request.categories())
.flatMap(category -> categoryClient.findByName(category)
.next())
.collectList()
.flatMap(categoryRests -> {
var brand = new Brand();
brand.setBrandName(request.brandName());
brand.setStatus(true);
brand.setDescription(request.description());
brand.setImageUrl(request.imageUrl());
brand.setNoOfProducts(0L);
return brandRepository.save(brand)
.flatMap(b -> {
for (CategoryRest categoryRest: categoryRests) {
var brandCategory = new BrandCategory(b.getBrandId(), categoryRest.categoryId());
brandCategoryRepository.save(brandCategory);
}
return Mono.just(new BrandCategoryRest(b, categoryRests));
});
})
.map(brandCategoryRest -> BrandRest.of(brandCategoryRest.brandRest(), brandCategoryRest.categoryRests()));
}
In this, the brandRepository.save(brand) is working fine and saving the entity in the database. But
brandCategoryRepository.save(brandCategory) is not saving any record in the database.
I am using postgresql as database.
New contributor
Naveen Kumar is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.