Created crud operation for evaluation criteria,faq,lookUp data and document

This commit is contained in:
harish
2024-08-26 17:05:03 +05:30
parent 049b53ac46
commit 948e5ec31d
33 changed files with 1075 additions and 77 deletions

View File

@@ -0,0 +1,65 @@
package net.gepafin.tendermanagement.dao;
import net.gepafin.tendermanagement.entities.LookUpDataEntity;
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.ResourceNotFoundException;
import net.gepafin.tendermanagement.web.rest.api.errors.Status;
import net.gepafin.tendermanagement.config.Translator;
import net.gepafin.tendermanagement.constants.GepafinConstant;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
@Component
public class LookUpDataDao {
@Autowired
private LookUpDataRepository lookUpDataRepository;
public LookUpDataResponseBean createLookUpData(LookUpDataRequest lookUpDataReq) {
LookUpDataEntity entity = convertLookUpDataReqToLookUpDataEntity(lookUpDataReq);
return convertLookUpDataEntityToResponseBean(entity);
}
private LookUpDataEntity convertLookUpDataReqToLookUpDataEntity(LookUpDataRequest lookUpDataReq) {
LookUpDataEntity entity = new LookUpDataEntity();
entity.setTitle(lookUpDataReq.getTitle());
entity.setType(lookUpDataReq.getType().getValue());
entity.setValue(lookUpDataReq.getValue());
lookUpDataRepository.save(entity);
return entity;
}
public LookUpDataResponseBean getLookUpDataById(Long id) {
return lookUpDataRepository.findById(id)
.map(this::convertLookUpDataEntityToResponseBean)
.orElseThrow(() -> new ResourceNotFoundException(Status.NOT_FOUND, Translator.toLocale(GepafinConstant.LOOKUP_DATA_NOT_FOUND)));
}
public LookUpDataResponseBean updateLookUpData(Long id, LookUpDataRequest lookUpDataReq) {
LookUpDataEntity entity = lookUpDataRepository.findById(id)
.orElseThrow(() -> new ResourceNotFoundException(Status.NOT_FOUND, Translator.toLocale(GepafinConstant.LOOKUP_DATA_NOT_FOUND)));
entity.setTitle(lookUpDataReq.getTitle());
entity.setType(lookUpDataReq.getType().getValue());
entity.setValue(lookUpDataReq.getValue());
lookUpDataRepository.save(entity);
return convertLookUpDataEntityToResponseBean(entity);
}
public void deleteLookUpData(Long id) {
LookUpDataEntity entity = lookUpDataRepository.findById(id)
.orElseThrow(() -> new ResourceNotFoundException(Status.NOT_FOUND, Translator.toLocale(GepafinConstant.LOOKUP_DATA_NOT_FOUND)));
lookUpDataRepository.deleteById(entity.getId());
}
private LookUpDataResponseBean convertLookUpDataEntityToResponseBean(LookUpDataEntity entity) {
LookUpDataResponseBean response = new LookUpDataResponseBean();
response.setId(entity.getId());
response.setTitle(entity.getTitle());
response.setType(LookUpDataEntity.LookUpDataTypeEnum.valueOf(entity.getType()));
response.setValue(entity.getValue());
response.setCreatedDate(entity.getCreatedDate());
response.setUpdatedDate(entity.getUpdatedDate());
return response;
}
}