added validation in call api

This commit is contained in:
harish
2024-09-03 14:52:07 +05:30
parent c05a5d22ee
commit 5b2cfcd594
7 changed files with 23 additions and 2 deletions

View File

@@ -18,7 +18,7 @@ public class GepafinConstant {
public static final String ROLE_FETCH_SUCCESS_MSG = "role.fetch.success";
public static final String ROLE_NOT_FOUND = "role.not.found";
public static final String VALUE_CANNOT_BE_EMPTY = "lookupdata.value.cannot.be.empty";
public static final String REGION_CREATED_SUCCESS_MSG = "region.created.success";
public static final String REGION_UPDATED_SUCCESS_MSG = "region.updated.success";
public static final String GET_REGION_SUCCESS_MSG = "get.region.success";

View File

@@ -8,6 +8,7 @@ import java.util.Objects;
import java.util.stream.Collectors;
import net.gepafin.tendermanagement.model.response.*;
import net.gepafin.tendermanagement.service.LookUpDataService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.util.StringUtils;
@@ -65,7 +66,8 @@ public class CallDao {
@Autowired
private RegionRepository regionRepository;
@Autowired
private LookUpDataService lookUpDataService;
@Autowired
private LookUpDataRepository lookUpDataRepository;
@@ -405,6 +407,7 @@ public class CallDao {
LookUpDataEntity newEntity = new LookUpDataEntity();
newEntity.setValue(req.getValue());
newEntity.setType(type.getValue());
lookUpDataService.validateLookUpDataEntity(newEntity);
return lookUpDataRepository.save(newEntity);
}

View File

@@ -5,6 +5,7 @@ import net.gepafin.tendermanagement.entities.LookUpDataEntity.LookUpDataTypeEnum
import net.gepafin.tendermanagement.model.request.LookUpDataRequest;
import net.gepafin.tendermanagement.model.response.LookUpDataResponseBean;
import net.gepafin.tendermanagement.repositories.LookUpDataRepository;
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 net.gepafin.tendermanagement.config.Translator;
@@ -30,10 +31,18 @@ public class LookUpDataDao {
entity.setTitle(lookUpDataReq.getTitle());
entity.setType(lookUpDataReq.getType().getValue());
entity.setValue(lookUpDataReq.getValue());
validateLookUpDataEntity(entity);
lookUpDataRepository.save(entity);
return entity;
}
public void validateLookUpDataEntity(LookUpDataEntity entity) {
if (entity.getValue() == null || entity.getValue().trim().isEmpty()) {
throw new CustomValidationException(Status.BAD_REQUEST, Translator.toLocale(GepafinConstant.VALUE_CANNOT_BE_EMPTY));
}
}
public LookUpDataResponseBean getLookUpDataById(Long id) {
return lookUpDataRepository.findById(id)
.map(this::convertLookUpDataEntityToResponseBean)

View File

@@ -1,5 +1,6 @@
package net.gepafin.tendermanagement.service;
import net.gepafin.tendermanagement.entities.LookUpDataEntity;
import net.gepafin.tendermanagement.entities.LookUpDataEntity.LookUpDataTypeEnum;
import net.gepafin.tendermanagement.model.request.LookUpDataRequest;
import net.gepafin.tendermanagement.model.response.LookUpDataResponseBean;
@@ -15,6 +16,7 @@ public interface LookUpDataService {
LookUpDataResponseBean updateLookUpData(Long id, LookUpDataRequest lookUpDataReq);
void deleteLookUpData(Long id);
void validateLookUpDataEntity(LookUpDataEntity lookUpDataEntity);
List<LookUpDataResponseBean> getLookUpDataByType(List<LookUpDataTypeEnum> type);
}

View File

@@ -1,6 +1,7 @@
package net.gepafin.tendermanagement.service.impl;
import net.gepafin.tendermanagement.dao.LookUpDataDao;
import net.gepafin.tendermanagement.entities.LookUpDataEntity;
import net.gepafin.tendermanagement.entities.LookUpDataEntity.LookUpDataTypeEnum;
import net.gepafin.tendermanagement.model.request.LookUpDataRequest;
import net.gepafin.tendermanagement.model.response.LookUpDataResponseBean;
@@ -31,6 +32,10 @@ public class LookUpDataServiceImpl implements LookUpDataService {
return lookUpDataDao.updateLookUpData(id, lookUpDataReq);
}
public void validateLookUpDataEntity(LookUpDataEntity lookUpDataEntity)
{
lookUpDataDao.validateLookUpDataEntity(lookUpDataEntity);
}
@Override
public void deleteLookUpData(Long id) {
lookUpDataDao.deleteLookUpData(id);