Add few APIs related to call and Update Responses for Call Controller

This commit is contained in:
harish
2024-08-27 16:55:50 +05:30
parent 157168a59e
commit 21fc9a4b91
17 changed files with 136 additions and 36 deletions

View File

@@ -379,10 +379,16 @@ public class CallDao {
return lookUpDataResponse;
}
public CallEntity getCallById(Long callId) {
public CallEntity validateCall(Long callId) {
return callRepository.findById(callId).orElseThrow(() -> new CustomValidationException(Status.VALIDATION_ERROR,
Translator.toLocale(GepafinConstant.CALL_NOT_FOUND)));
}
public CreateCallResponseBean getCallById(Long callId) {
CallEntity callEntity = callRepository.findById(callId)
.orElseThrow(() -> new CustomValidationException(Status.VALIDATION_ERROR,
Translator.toLocale(GepafinConstant.CALL_NOT_FOUND)));
return convertToCallResponseBean(callEntity);
}
public CreateCallResponseBean createCallStep2(CreateCallRequestStep2 createCallRequest, Long userId) {
CreateCallResponseBean createCallResponseBean = null;
@@ -434,7 +440,7 @@ public class CallDao {
}
public CreateCallResponseBean updateCallStep1(Long callId, UpdateCallRequestStep1 updateCallRequest, Long userId) {
CallEntity callEntity = getCallById(callId);
CallEntity callEntity = validateCall(callId);
isValidDateRange(updateCallRequest, callEntity);
setIfUpdated(callEntity::getName, callEntity::setName, updateCallRequest.getName());
setIfUpdated(callEntity::getDescriptionShort, callEntity::setDescriptionShort,
@@ -454,6 +460,26 @@ public class CallDao {
return createCallResponseBean;
}
public CallDetailsResponseBean convertToCallDetailsResponseBean(CallEntity callEntity) {
CallDetailsResponseBean callDetailsResponseBean = new CallDetailsResponseBean();
callDetailsResponseBean.setId(callEntity.getId());
callDetailsResponseBean.setName(callEntity.getName());
callDetailsResponseBean.setDates(List.of(callEntity.getStartDate(), callEntity.getEndDate()));
callDetailsResponseBean.setDescriptionShort(callEntity.getDescriptionShort());
callDetailsResponseBean.setDescriptionLong(callEntity.getDescriptionLong());
callDetailsResponseBean.setStatus(CallTypeEnum.valueOf(callEntity.getStatus()));
callDetailsResponseBean.setRegionId(callEntity.getRegion().getId());
callDetailsResponseBean.setAmount(callEntity.getAmount());
callDetailsResponseBean.setAmountMax(callEntity.getAmountMax());
callDetailsResponseBean.setContactInfo(callEntity.getContactInfo());
callDetailsResponseBean.setSubmissionMethod(callEntity.getSubmissionMethod());
callDetailsResponseBean.setThreshold(callEntity.getThreshold());
callDetailsResponseBean.setDocumentationReqested(callEntity.getDocumentationRequested());
callDetailsResponseBean.setPriorityArea(callEntity.getPriorityArea());
callDetailsResponseBean.setCreatedDate(callEntity.getCreatedDate());
callDetailsResponseBean.setUpdatedDate(callEntity.getUpdatedDate());
return callDetailsResponseBean;
}
private CreateCallResponseBean getCallResponseBean(CallEntity callEntity) {
List<DocumentEntity> documentEntities = documentRepository.findByCallIdAndType(callEntity.getId(),
DocumentTypeEnum.DOCUMENT.getValue());
@@ -476,10 +502,10 @@ public class CallDao {
createCallResponseBean.setCheckList(checkList);
return createCallResponseBean;
}
public List<CreateCallResponseBean> getAllCalls() {
return callRepository.findAll()
public List<CallDetailsResponseBean> getAllCalls() {
return callRepository.findAll()
.stream()
.map(callEntity -> Utils.convertObject(callEntity, CreateCallResponseBean.class))
.map(this::convertToCallDetailsResponseBean)
.collect(Collectors.toList());
}
}