added validation in call api
This commit is contained in:
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user