Refactored code for faq

This commit is contained in:
rajesh
2024-09-04 19:21:32 +05:30
parent e51c86806a
commit 286baa9c21
15 changed files with 203 additions and 245 deletions

View File

@@ -2,6 +2,7 @@ package net.gepafin.tendermanagement.dao;
import net.gepafin.tendermanagement.entities.LookUpDataEntity;
import net.gepafin.tendermanagement.entities.LookUpDataEntity.LookUpDataTypeEnum;
import net.gepafin.tendermanagement.model.request.LookUpDataReq;
import net.gepafin.tendermanagement.model.request.LookUpDataRequest;
import net.gepafin.tendermanagement.model.response.LookUpDataResponseBean;
import net.gepafin.tendermanagement.repositories.LookUpDataRepository;
@@ -82,6 +83,23 @@ public class LookUpDataDao {
.map(this::convertLookUpDataEntityToResponseBean)
.collect(Collectors.toList());
}
public LookUpDataEntity getOrCreateLookUpDataEntity(LookUpDataReq req,
LookUpDataEntity.LookUpDataTypeEnum type) {
if (req.getLookUpDataId() == null || req.getLookUpDataId().equals(0l)) {
LookUpDataEntity newEntity = new LookUpDataEntity();
newEntity.setTitle(req.getTitle());
newEntity.setValue(req.getValue());
newEntity.setResponse(req.getResponse());
newEntity.setType(type.getValue());
validateLookUpDataEntity(newEntity);
return lookUpDataRepository.save(newEntity);
}
return lookUpDataRepository.findById(req.getLookUpDataId())
.orElseThrow(() -> new ResourceNotFoundException(Status.NOT_FOUND,
Translator.toLocale(GepafinConstant.LOOK_UP_DATA_NOT_VALID_MSG)));
}
}