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

@@ -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)