Updated code
This commit is contained in:
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user