Refactored code for faq
This commit is contained in:
@@ -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)));
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user