Updated code

This commit is contained in:
rajesh
2024-11-13 20:48:38 +05:30
parent 2f7ca1b42a
commit 1fc54445b5

View File

@@ -21,6 +21,7 @@ import org.springframework.stereotype.Component;
import jakarta.servlet.http.HttpServletRequest;
import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;
@@ -36,16 +37,19 @@ public class BeneficiaryPreferredCallDao {
private Validator validator;
public BeneficiaryPreferredCallResponseBean createBeneficiaryPreferredCall(HttpServletRequest httpServletRequest, BeneficiaryPreferredCallReq request,UserEntity user) {
public BeneficiaryPreferredCallResponseBean createBeneficiaryPreferredCall(HttpServletRequest httpServletRequest, BeneficiaryPreferredCallReq request, UserEntity user) {
log.info("Creating new beneficiary preferred call with details: {}", request);
validator.validateUserWithCompany(httpServletRequest, request.getCompanyId());
boolean exists = beneficiaryPreferredCallRepository
.findByUserIdAndCallIdAndCompanyIdAndIsDeletedFalse(user.getId(), request.getCallId(), request.getCompanyId())
.isPresent();
if (exists) {
throw new CustomValidationException(Status.VALIDATION_ERROR,Translator.toLocale(GepafinConstant.DUPLICATE_BENEFICIARY_CALL));
Optional<BeneficiaryPreferredCallEntity> existingCall = beneficiaryPreferredCallRepository
.findByUserIdAndCallIdAndCompanyIdAndIsDeletedFalse(user.getId(), request.getCallId(), request.getCompanyId());
if (existingCall.isPresent()) {
log.warn("Duplicate beneficiary preferred call detected: {}", existingCall.get());
throw new CustomValidationException(Status.VALIDATION_ERROR, Translator.toLocale(GepafinConstant.DUPLICATE_BENEFICIARY_CALL));
}
BeneficiaryPreferredCallEntity entity = convertRequestToEntity(request,user);
BeneficiaryPreferredCallEntity entity = convertRequestToEntity(request, user);
entity = beneficiaryPreferredCallRepository.save(entity);
log.info("Beneficiary preferred call created with ID: {}", entity.getId());
return convertEntityToResponse(entity);