Added validation in preferred call

This commit is contained in:
harish
2024-11-13 17:20:30 +05:30
parent c86a4cf91c
commit 2f7ca1b42a
5 changed files with 13 additions and 0 deletions

View File

@@ -10,6 +10,7 @@ import net.gepafin.tendermanagement.model.request.BeneficiaryPreferredCallReq;
import net.gepafin.tendermanagement.model.response.BeneficiaryPreferredCallResponseBean;
import net.gepafin.tendermanagement.repositories.BeneficiaryPreferredCallRepository;
import net.gepafin.tendermanagement.util.Validator;
import net.gepafin.tendermanagement.web.rest.api.errors.CustomValidationException;
import net.gepafin.tendermanagement.web.rest.api.errors.ResourceNotFoundException;
import net.gepafin.tendermanagement.web.rest.api.errors.Status;
import org.slf4j.Logger;
@@ -38,6 +39,12 @@ public class BeneficiaryPreferredCallDao {
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));
}
BeneficiaryPreferredCallEntity entity = convertRequestToEntity(request,user);
entity = beneficiaryPreferredCallRepository.save(entity);
log.info("Beneficiary preferred call created with ID: {}", entity.getId());
@@ -53,6 +60,7 @@ public class BeneficiaryPreferredCallDao {
entity.setCallId(request.getCallId());
entity.setUserId(userEntity.getId());
entity.setCompanyId(request.getCompanyId());
entity.setIsDeleted( false);
return entity;
}