Created crud operation for evaluation criteria,faq,lookUp data and document
This commit is contained in:
@@ -112,7 +112,7 @@ public class CallDao {
|
||||
return callEntity;
|
||||
}
|
||||
|
||||
public List<EvaluationCriteriaEntity> convertToEvaluationCriteriaEntities(List<EvaluationCriteriaReq> criteriaReqList, CallEntity callEntity) {
|
||||
public List<EvaluationCriteriaEntity> convertListOfEvaluationCriteriaReqToEvaluationCriteriaEntities(List<EvaluationCriteriaReq> criteriaReqList, CallEntity callEntity) {
|
||||
List<EvaluationCriteriaEntity> evaluationCriteriaEntities = criteriaReqList.stream().map(req -> convertToEvaluationCriteriaEntity(req, callEntity)).collect(Collectors.toList());
|
||||
evaluationCriteriaRepository.saveAll(evaluationCriteriaEntities);
|
||||
return evaluationCriteriaEntities;
|
||||
@@ -120,7 +120,7 @@ public class CallDao {
|
||||
|
||||
private EvaluationCriteriaEntity convertToEvaluationCriteriaEntity(EvaluationCriteriaReq criteriaReq, CallEntity callEntity) {
|
||||
EvaluationCriteriaEntity criteriaEntity = new EvaluationCriteriaEntity();
|
||||
validateEvolutionCrieteriaEntity(criteriaReq.getName());
|
||||
validateEvolutionCrieteriaEntity(criteriaReq.getName(),criteriaReq.getScore());
|
||||
criteriaEntity.setName(criteriaReq.getName());
|
||||
criteriaEntity.setDescription(criteriaReq.getValue());
|
||||
criteriaEntity.setScore(criteriaReq.getScore());
|
||||
@@ -156,7 +156,7 @@ public class CallDao {
|
||||
return faqEntities;
|
||||
}
|
||||
|
||||
private FaqEntity convertToFaqEntity(FaqReq faqReq, CallEntity callEntity, Long userId) {
|
||||
public FaqEntity convertToFaqEntity(FaqReq faqReq, CallEntity callEntity, Long userId) {
|
||||
FaqEntity faqEntity = new FaqEntity();
|
||||
validateFaqEntity(faqReq.getQuestion());
|
||||
UserEntity userEntity= userRepository.findById(userId)
|
||||
@@ -193,10 +193,13 @@ public class CallDao {
|
||||
// }
|
||||
}
|
||||
|
||||
public void validateEvolutionCrieteriaEntity(String name) {
|
||||
public void validateEvolutionCrieteriaEntity(String name,Integer score) {
|
||||
if (!StringUtils.hasText(name)) {
|
||||
throw new CustomValidationException(Status.VALIDATION_ERROR, Translator.toLocale(GepafinConstant.NAME_NOT_EMPTY_MSG));
|
||||
}
|
||||
if (score == null || score <= 0) {
|
||||
throw new CustomValidationException(Status.VALIDATION_ERROR, Translator.toLocale(GepafinConstant.SCORE_NOT_NULL_MSG));
|
||||
}
|
||||
}
|
||||
|
||||
public void validateCallEntity(CreateCallRequestStep1 createCallRequest) {
|
||||
@@ -366,6 +369,11 @@ public class CallDao {
|
||||
return createCallResponseBean;
|
||||
|
||||
}
|
||||
public List<EvaluationCriteriaEntity> convertToEvaluationCriteriaEntities(List<EvaluationCriteriaReq> criteriaReqList, CallEntity callEntity) {
|
||||
List<EvaluationCriteriaEntity> evaluationCriteriaEntities = criteriaReqList.stream().map(req -> convertToEvaluationCriteriaEntity(req, callEntity)).collect(Collectors.toList());
|
||||
evaluationCriteriaRepository.saveAll(evaluationCriteriaEntities);
|
||||
return evaluationCriteriaEntities;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -1,8 +1,7 @@
|
||||
package net.gepafin.tendermanagement.dao;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import org.apache.commons.io.FilenameUtils;
|
||||
@@ -13,14 +12,20 @@ import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import net.gepafin.tendermanagement.config.Translator;
|
||||
import net.gepafin.tendermanagement.constants.GepafinConstant;
|
||||
import net.gepafin.tendermanagement.entities.CallEntity;
|
||||
import net.gepafin.tendermanagement.entities.DocumentEntity;
|
||||
import net.gepafin.tendermanagement.enums.DocumentTypeEnum;
|
||||
import net.gepafin.tendermanagement.model.response.DocumentResponseBean;
|
||||
import net.gepafin.tendermanagement.repositories.CallRepository;
|
||||
import net.gepafin.tendermanagement.repositories.DocumentRepository;
|
||||
import net.gepafin.tendermanagement.service.AmazonS3Service;
|
||||
import net.gepafin.tendermanagement.util.Utils;
|
||||
import net.gepafin.tendermanagement.web.rest.api.errors.ResourceNotFoundException;
|
||||
import net.gepafin.tendermanagement.web.rest.api.errors.Status;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@Component
|
||||
public class DocumentDao {
|
||||
@@ -34,21 +39,32 @@ public class DocumentDao {
|
||||
@Autowired
|
||||
private CallDao callDao;
|
||||
|
||||
public List<DocumentResponseBean> uploadFiles(List<MultipartFile> files, DocumentTypeEnum fileType) {
|
||||
List<DocumentEntity> documentEntities = new ArrayList<>();
|
||||
@Value("${aws.s3.bucket.name}")
|
||||
private String bucketName;
|
||||
|
||||
@Value("${aws.s3.url.folder}")
|
||||
private String s3Folder;
|
||||
|
||||
@Value("${aws.s3.url}")
|
||||
private String s3Url;
|
||||
|
||||
@Autowired
|
||||
private CallRepository callRepository;
|
||||
|
||||
public List<DocumentResponseBean> uploadFiles(List<MultipartFile> files,Long callId, DocumentTypeEnum fileType) {
|
||||
List<DocumentEntity> documentEntities = new ArrayList<>();
|
||||
CallEntity callEntity=callRepository.findById(callId).orElseThrow(() -> new ResourceNotFoundException(Status.NOT_FOUND, Translator.toLocale(GepafinConstant.CALL_NOT_FOUND)));
|
||||
for (MultipartFile file : files) {
|
||||
try {
|
||||
String extension = FilenameUtils.getExtension(file.getOriginalFilename());
|
||||
String fileName = StringUtils.cleanPath(file.getOriginalFilename());
|
||||
String firstNameContain = fileName.substring(0, fileName.lastIndexOf('.'));
|
||||
fileName = (firstNameContain + "." + extension);
|
||||
String filepath = amazonS3Service.upload(fileName,file);
|
||||
DocumentEntity documentEntity = new DocumentEntity();
|
||||
documentEntity.setFileName(fileName);
|
||||
documentEntity.setType(fileType.getValue());
|
||||
documentEntity.setFilePath(filepath);
|
||||
documentEntities.add(documentEntity);
|
||||
uploadFileOnAmazonS3 result = uploadFileOnAmazonS3(file);
|
||||
if(result!=null) {
|
||||
DocumentEntity documentEntity = new DocumentEntity();
|
||||
documentEntity.setFileName(result.fileName());
|
||||
documentEntity.setCall(callEntity);
|
||||
documentEntity.setType(fileType.getValue());
|
||||
documentEntity.setFilePath(result.filepath());
|
||||
documentEntities.add(documentEntity);
|
||||
}
|
||||
} catch (IOException e) {}
|
||||
}
|
||||
documentRepository.saveAll(documentEntities);
|
||||
@@ -57,14 +73,62 @@ public class DocumentDao {
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
public void deleteFile(Long documentId) {
|
||||
DocumentEntity documentEntity = documentRepository.findById(documentId)
|
||||
.orElseThrow(() -> new ResourceNotFoundException(Status.VALIDATION_ERROR,
|
||||
Translator.toLocale(GepafinConstant.DOCUMENT_NOT_FOUND)));
|
||||
private uploadFileOnAmazonS3 uploadFileOnAmazonS3(MultipartFile file) throws IOException {
|
||||
String extension = FilenameUtils.getExtension(file.getOriginalFilename());
|
||||
String fileName = StringUtils.cleanPath(file.getOriginalFilename());
|
||||
String firstNameContain = fileName.substring(0, fileName.lastIndexOf('.'));
|
||||
fileName = (firstNameContain + "." + extension);
|
||||
String filepath = amazonS3Service.upload(fileName, file);
|
||||
uploadFileOnAmazonS3 result = new uploadFileOnAmazonS3(fileName, filepath);
|
||||
return result;
|
||||
}
|
||||
|
||||
String fileName = Utils.extractFileName(documentEntity.getFilePath());
|
||||
amazonS3Service.delete(fileName);
|
||||
documentRepository.delete(documentEntity);
|
||||
private record uploadFileOnAmazonS3(String fileName, String filepath) {
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
public void deleteFile(Long documentId){
|
||||
DocumentEntity documentEntity = getDocumentEntity(documentId);
|
||||
String fileName= Utils.extractFileName(documentEntity.getFilePath());
|
||||
deleteFileOnAmazonS3(fileName);
|
||||
documentRepository.delete(documentEntity);
|
||||
}
|
||||
|
||||
private DocumentEntity deleteFileOnAmazonS3(String fileName) {
|
||||
try {
|
||||
amazonS3Service.delete(fileName);
|
||||
}catch (Exception e){}
|
||||
return null;
|
||||
}
|
||||
|
||||
private DocumentEntity getDocumentEntity(Long documentId) {
|
||||
Optional<DocumentEntity> documentEntity= documentRepository.findById(documentId);
|
||||
if(documentEntity.isEmpty()){
|
||||
throw new ResourceNotFoundException(Status.VALIDATION_ERROR, Translator.toLocale(GepafinConstant.DOCUMENT_NOT_FOUND));
|
||||
}
|
||||
return documentEntity.orElse(null);
|
||||
}
|
||||
|
||||
public DocumentResponseBean updateDocument(Long documentId, MultipartFile file, DocumentTypeEnum documentTypeEnum){
|
||||
DocumentEntity documentEntity = getDocumentEntity(documentId);
|
||||
String fileName= Utils.extractFileName(documentEntity.getFilePath());
|
||||
deleteFileOnAmazonS3(fileName);
|
||||
uploadFileOnAmazonS3 result= null;
|
||||
try {
|
||||
result = uploadFileOnAmazonS3(file);
|
||||
} catch (IOException e) {}
|
||||
if(result!=null){
|
||||
documentEntity.setFilePath(result.filepath);
|
||||
documentEntity.setFileName(result.fileName);
|
||||
documentEntity.setType(documentTypeEnum.getValue());
|
||||
documentRepository.save(documentEntity);
|
||||
}
|
||||
return callDao.convertToDocumentResponseBean(documentEntity);
|
||||
}
|
||||
public DocumentResponseBean getDocument(Long documentId) {
|
||||
Optional<DocumentEntity> documentEntity= documentRepository.findById(documentId);
|
||||
if(documentEntity.isEmpty()){
|
||||
new ResourceNotFoundException(Status.VALIDATION_ERROR, Translator.toLocale(GepafinConstant.DOCUMENT_NOT_FOUND));
|
||||
}
|
||||
return callDao.convertToDocumentResponseBean(documentEntity.orElse(null));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,75 @@
|
||||
package net.gepafin.tendermanagement.dao;
|
||||
|
||||
import net.gepafin.tendermanagement.config.Translator;
|
||||
import net.gepafin.tendermanagement.constants.GepafinConstant;
|
||||
import net.gepafin.tendermanagement.entities.CallEntity;
|
||||
import net.gepafin.tendermanagement.entities.EvaluationCriteriaEntity;
|
||||
import net.gepafin.tendermanagement.model.request.EvaluationCriteriaRequest;
|
||||
import net.gepafin.tendermanagement.model.response.EvaluationCriteriaResponseBean;
|
||||
import net.gepafin.tendermanagement.repositories.CallRepository;
|
||||
import net.gepafin.tendermanagement.repositories.EvaluationCriteriaRepository;
|
||||
import net.gepafin.tendermanagement.web.rest.api.errors.ResourceNotFoundException;
|
||||
import net.gepafin.tendermanagement.web.rest.api.errors.Status;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.dao.EmptyResultDataAccessException;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
|
||||
@Component
|
||||
public class EvaluationCriteriaDao {
|
||||
|
||||
@Autowired
|
||||
private EvaluationCriteriaRepository repository;
|
||||
|
||||
@Autowired
|
||||
private CallRepository callRepository;
|
||||
|
||||
public EvaluationCriteriaResponseBean createEvaluationCriteria(EvaluationCriteriaRequest evaluationCriteriaRequest) {
|
||||
EvaluationCriteriaEntity entity = convertEvaluationCriteriaRequestToEvaluationCriteriaEntity(evaluationCriteriaRequest);
|
||||
return convertEvaluationCriteriaEntityEvaluationCriteriaToResponseBean(entity);
|
||||
}
|
||||
|
||||
private EvaluationCriteriaEntity convertEvaluationCriteriaRequestToEvaluationCriteriaEntity(EvaluationCriteriaRequest evaluationCriteriaRequest) {
|
||||
EvaluationCriteriaEntity entity = new EvaluationCriteriaEntity();
|
||||
CallEntity callEntity= callRepository.findById(evaluationCriteriaRequest.getCallId())
|
||||
.orElseThrow(() -> new ResourceNotFoundException(Status.VALIDATION_ERROR, Translator.toLocale(GepafinConstant.CALL_NOT_FOUND)));
|
||||
entity.setCall(callEntity);
|
||||
entity.setName(evaluationCriteriaRequest.getName());
|
||||
entity.setDescription(evaluationCriteriaRequest.getDescription());
|
||||
entity.setScore(evaluationCriteriaRequest.getScore());
|
||||
entity = repository.save(entity);
|
||||
return entity;
|
||||
}
|
||||
|
||||
public EvaluationCriteriaResponseBean getEvaluationCriteriaById(Long id) {
|
||||
return repository.findById(id)
|
||||
.map(this::convertEvaluationCriteriaEntityEvaluationCriteriaToResponseBean)
|
||||
.orElseThrow(() -> new ResourceNotFoundException(Status.NOT_FOUND, Translator.toLocale(GepafinConstant.EVALUATION_CRITERIA_NOT_FOUND)));
|
||||
}
|
||||
|
||||
public EvaluationCriteriaResponseBean updateEvaluationCriteria(Long id, EvaluationCriteriaRequest request) {
|
||||
EvaluationCriteriaEntity entity = repository.findById(id)
|
||||
.orElseThrow(() -> new ResourceNotFoundException(Status.NOT_FOUND, Translator.toLocale(GepafinConstant.EVALUATION_CRITERIA_NOT_FOUND)));
|
||||
entity = convertEvaluationCriteriaRequestToEvaluationCriteriaEntity(request);
|
||||
return convertEvaluationCriteriaEntityEvaluationCriteriaToResponseBean(entity);
|
||||
}
|
||||
|
||||
public void deleteEvaluationCriteria(Long id) {
|
||||
try {
|
||||
repository.deleteById(id);
|
||||
} catch (EmptyResultDataAccessException e) {
|
||||
throw new ResourceNotFoundException(Status.NOT_FOUND, Translator.toLocale(GepafinConstant.EVALUATION_CRITERIA_NOT_FOUND));
|
||||
}
|
||||
}
|
||||
|
||||
private EvaluationCriteriaResponseBean convertEvaluationCriteriaEntityEvaluationCriteriaToResponseBean(EvaluationCriteriaEntity entity) {
|
||||
EvaluationCriteriaResponseBean response = new EvaluationCriteriaResponseBean();
|
||||
response.setId(entity.getId());
|
||||
response.setName(entity.getName());
|
||||
response.setDescription(entity.getDescription());
|
||||
response.setScore(entity.getScore());
|
||||
response.setCreatedDate(entity.getCreatedDate());
|
||||
response.setUpdatedDate(entity.getUpdatedDate());
|
||||
return response;
|
||||
}
|
||||
}
|
||||
96
src/main/java/net/gepafin/tendermanagement/dao/FaqDao.java
Normal file
96
src/main/java/net/gepafin/tendermanagement/dao/FaqDao.java
Normal file
@@ -0,0 +1,96 @@
|
||||
package net.gepafin.tendermanagement.dao;
|
||||
import net.gepafin.tendermanagement.config.Translator;
|
||||
import net.gepafin.tendermanagement.constants.GepafinConstant;
|
||||
import net.gepafin.tendermanagement.entities.CallEntity;
|
||||
import net.gepafin.tendermanagement.entities.FaqEntity;
|
||||
import net.gepafin.tendermanagement.entities.UserEntity;
|
||||
import net.gepafin.tendermanagement.model.request.FaqReq;
|
||||
import net.gepafin.tendermanagement.model.response.FaqResponseBean;
|
||||
import net.gepafin.tendermanagement.repositories.CallRepository;
|
||||
import net.gepafin.tendermanagement.repositories.FaqRepository;
|
||||
import net.gepafin.tendermanagement.repositories.UserRepository;
|
||||
import net.gepafin.tendermanagement.util.DateTimeUtil;
|
||||
import net.gepafin.tendermanagement.web.rest.api.errors.ResourceNotFoundException;
|
||||
import net.gepafin.tendermanagement.web.rest.api.errors.Status;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
@Component
|
||||
public class FaqDao {
|
||||
|
||||
@Autowired
|
||||
private FaqRepository faqRepository;
|
||||
|
||||
@Autowired
|
||||
private UserRepository userRepository;
|
||||
|
||||
@Autowired
|
||||
private CallDao callDao;
|
||||
|
||||
@Autowired
|
||||
private CallRepository callRepository;
|
||||
|
||||
public FaqResponseBean createFaq(FaqReq faqRequest,Long userId,Long callId) {
|
||||
FaqEntity entity = new FaqEntity();
|
||||
CallEntity callEntity=callRepository.findById(callId).orElseThrow(() -> new ResourceNotFoundException(Status.NOT_FOUND, Translator.toLocale(GepafinConstant.CALL_NOT_FOUND)));
|
||||
entity= callDao.convertToFaqEntity(faqRequest,callEntity,userId);
|
||||
faqRepository.save(entity);
|
||||
return convertFaqEntityToResponseBean(entity);
|
||||
}
|
||||
|
||||
public FaqResponseBean getFaqById(Long id) {
|
||||
return faqRepository.findById(id)
|
||||
.map(this::convertFaqEntityToResponseBean)
|
||||
.orElseThrow(() -> new ResourceNotFoundException(Status.NOT_FOUND, Translator.toLocale(GepafinConstant.FAQ_NOT_FOUND)));
|
||||
}
|
||||
|
||||
public FaqResponseBean updateFaq(Long id, FaqReq faqRequest,Long userId) {
|
||||
FaqEntity entity = faqRepository.findById(id)
|
||||
.orElseThrow(() -> new ResourceNotFoundException(Status.NOT_FOUND,Translator.toLocale(GepafinConstant.FAQ_NOT_FOUND)));
|
||||
updateFaqEntity(entity,faqRequest,userId,entity.getCall());
|
||||
faqRepository.save(entity);
|
||||
return convertFaqEntityToResponseBean(entity);
|
||||
}
|
||||
|
||||
public void deleteFaq(Long id) {
|
||||
FaqEntity entity = faqRepository.findById(id)
|
||||
.orElseThrow(() -> new ResourceNotFoundException(Status.NOT_FOUND,Translator.toLocale(GepafinConstant.FAQ_NOT_FOUND)));
|
||||
faqRepository.deleteById(entity.getId());
|
||||
|
||||
}
|
||||
|
||||
private FaqResponseBean convertFaqEntityToResponseBean(FaqEntity entity) {
|
||||
FaqResponseBean response = new FaqResponseBean();
|
||||
response.setId(entity.getId());
|
||||
response.setUserId(entity.getUser().getId());
|
||||
response.setIsVisible(entity.getIsVisible());
|
||||
response.setUpdatedDate(entity.getUpdatedDate());
|
||||
response.setCreatedDate(entity.getCreatedDate());
|
||||
response.setQuestionShort(entity.getQuestionShort());
|
||||
response.setQuestion(entity.getQuestion());
|
||||
response.setResponseShort(entity.getResponseShort());
|
||||
response.setResponse(entity.getResponse());
|
||||
response.setResponseDate(entity.getResponseDate());
|
||||
return response;
|
||||
}
|
||||
private void updateFaqEntity(FaqEntity faqEntity, FaqReq faqReq, Long userId,CallEntity callEntity) {
|
||||
faqEntity.setQuestion(faqReq.getQuestion());
|
||||
UserEntity userEntity= userRepository.findById(userId)
|
||||
.orElseThrow(() -> new ResourceNotFoundException(Status.VALIDATION_ERROR, Translator.toLocale(GepafinConstant.LOOK_UP_DATA_NOT_VALID_MSG)));
|
||||
faqEntity.setUser(userEntity);
|
||||
faqEntity.setIsVisible(true);
|
||||
if(faqReq.getIsVisible()!=null){
|
||||
faqEntity.setIsVisible(faqReq.getIsVisible());
|
||||
}
|
||||
faqEntity.setQuestionShort(faqReq.getQuestionShort());
|
||||
faqEntity.setQuestion(faqReq.getQuestion());
|
||||
if(faqReq.getResponse()!=null ||faqReq.getResponseShort()!=null){
|
||||
faqEntity.setResponseDate(DateTimeUtil.DateServerToUTC(LocalDateTime.now()));
|
||||
}
|
||||
faqEntity.setResponseShort(faqReq.getResponseShort());
|
||||
faqEntity.setResponse(faqReq.getResponse());
|
||||
faqEntity.setCall(callEntity);
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user