improved code quality and tested with test data
This commit is contained in:
@@ -26,6 +26,7 @@ import com.billpaymentservice.bbps.dto.sentRequest.BillPaymentForwardRequest;
|
||||
import com.billpaymentservice.bbps.dto.sentRequest.FetchBillForwardRequest;
|
||||
import com.billpaymentservice.bbps.dto.sentRequest.FetchBillValidatestForwardRequest;
|
||||
import com.billpaymentservice.bbps.entites.AdditionalInfoBill;
|
||||
import com.billpaymentservice.bbps.entites.AdditionalInfoBillValidate;
|
||||
import com.billpaymentservice.bbps.entites.BBPSMastersData;
|
||||
import com.billpaymentservice.bbps.entites.BillMaster;
|
||||
import com.billpaymentservice.bbps.entites.BillValidation;
|
||||
@@ -218,32 +219,7 @@ public class Helper {
|
||||
Optional<BillerDetails> existingOpt = billerDataRespository.findByBillerId(newEntity.getBillerId());
|
||||
|
||||
if (existingOpt.isPresent()) {
|
||||
BillerDetails existing = existingOpt.get();
|
||||
|
||||
// Update base biller fields
|
||||
existing.setBillerName(newEntity.getBillerName());
|
||||
existing.setBillerAliasName(newEntity.getBillerAliasName());
|
||||
existing.setBillerDescription(newEntity.getBillerDescription());
|
||||
existing.setStatus(newEntity.getStatus());
|
||||
existing.setBillerCoverage(newEntity.getBillerCoverage());
|
||||
// ... (update other simple fields as needed)
|
||||
|
||||
// ✅ Clear and replace nested lists to avoid duplicate inserts
|
||||
existing.getBillerPaymentModes().clear();
|
||||
if (newEntity.getBillerPaymentModes() != null) {
|
||||
for (PaymentMode mode : newEntity.getBillerPaymentModes()) {
|
||||
mode.setBiller(existing);
|
||||
existing.getBillerPaymentModes().add(mode);
|
||||
}
|
||||
}
|
||||
existing.getBillerPaymentChannels().clear();
|
||||
if (newEntity.getBillerPaymentChannels() != null) {
|
||||
for (PaymentChannel channel : newEntity.getBillerPaymentChannels()) {
|
||||
channel.setBiller(existing);
|
||||
existing.getBillerPaymentChannels().add(channel);
|
||||
}
|
||||
}
|
||||
billerDataRespository.save(existing);
|
||||
//logic to be written
|
||||
}
|
||||
else {
|
||||
// brand new biller
|
||||
@@ -348,7 +324,18 @@ billMasterRepository.save(billMaster);
|
||||
.collect(Collectors.toList());
|
||||
billEntity.setCustomerParams(customerParams);
|
||||
}
|
||||
|
||||
if (responseWrapper.getAdditionalInfo() != null) {
|
||||
List<AdditionalInfoBillValidate> additionalInfos = responseWrapper.getAdditionalInfo()
|
||||
.stream()
|
||||
.map(info -> {
|
||||
AdditionalInfoBillValidate ai = modelMapper.map(info, AdditionalInfoBillValidate.class);
|
||||
ai.setBill(billEntity); // maintain relation
|
||||
return ai;
|
||||
})
|
||||
.collect(Collectors.toList());
|
||||
billEntity.setAdditionalInfo(additionalInfos);
|
||||
|
||||
}
|
||||
// ✅ Save everything (cascade handles child)
|
||||
|
||||
billValidationRepository.save(billEntity);
|
||||
|
||||
Reference in New Issue
Block a user