Updated code
This commit is contained in:
@@ -21,6 +21,7 @@ import org.springframework.stereotype.Component;
|
|||||||
import jakarta.servlet.http.HttpServletRequest;
|
import jakarta.servlet.http.HttpServletRequest;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Optional;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
|
||||||
@@ -39,12 +40,15 @@ public class BeneficiaryPreferredCallDao {
|
|||||||
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);
|
log.info("Creating new beneficiary preferred call with details: {}", request);
|
||||||
validator.validateUserWithCompany(httpServletRequest, request.getCompanyId());
|
validator.validateUserWithCompany(httpServletRequest, request.getCompanyId());
|
||||||
boolean exists = beneficiaryPreferredCallRepository
|
|
||||||
.findByUserIdAndCallIdAndCompanyIdAndIsDeletedFalse(user.getId(), request.getCallId(), request.getCompanyId())
|
Optional<BeneficiaryPreferredCallEntity> existingCall = beneficiaryPreferredCallRepository
|
||||||
.isPresent();
|
.findByUserIdAndCallIdAndCompanyIdAndIsDeletedFalse(user.getId(), request.getCallId(), request.getCompanyId());
|
||||||
if (exists) {
|
|
||||||
|
if (existingCall.isPresent()) {
|
||||||
|
log.warn("Duplicate beneficiary preferred call detected: {}", existingCall.get());
|
||||||
throw new CustomValidationException(Status.VALIDATION_ERROR, Translator.toLocale(GepafinConstant.DUPLICATE_BENEFICIARY_CALL));
|
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);
|
entity = beneficiaryPreferredCallRepository.save(entity);
|
||||||
log.info("Beneficiary preferred call created with ID: {}", entity.getId());
|
log.info("Beneficiary preferred call created with ID: {}", entity.getId());
|
||||||
|
|||||||
Reference in New Issue
Block a user