Added an optional parameter onlyPreferredCall in the getAllCalls API to filter the response and include only preferred calls
This commit is contained in:
@@ -656,13 +656,29 @@ public class CallDao {
|
||||
return createCallResponseBean;
|
||||
}
|
||||
|
||||
public List<CallDetailsResponseBean> getAllCalls(HttpServletRequest request,UserEntity user, Long companyId) {
|
||||
public List<CallDetailsResponseBean> getAllCalls(HttpServletRequest request,UserEntity user, Long companyId,Boolean onlyPreferredCall) {
|
||||
String type = user.getRoleEntity().getRoleType();
|
||||
List<String> callStatusList = CallStatusEnum.getStatusValues();
|
||||
if (Boolean.FALSE.equals(ROLE_SUPER_ADMIN.getValue().equals(type))) {
|
||||
callStatusList = List.of(CallStatusEnum.PUBLISH.getValue());
|
||||
}
|
||||
List<CallEntity> calls = callRepository.findByStatusInAndHubId(callStatusList, user.getHub().getId());
|
||||
List<CallEntity> calls;
|
||||
if (Boolean.TRUE.equals(onlyPreferredCall) && companyId == null) {
|
||||
throw new CustomValidationException(Status.VALIDATION_ERROR,
|
||||
Translator.toLocale(GepafinConstant.COMPANY_ID_REQUIRED_FOR_PREFERRED_CALL));
|
||||
}
|
||||
|
||||
if (Boolean.TRUE.equals(onlyPreferredCall)) {
|
||||
validator.validateUserWithCompany(request, companyId);
|
||||
List<BeneficiaryPreferredCallEntity> preferredCalls = beneficiaryPreferredCallRepository
|
||||
.findByUserIdAndCompanyIdAndIsDeletedFalse(user.getId(), companyId);
|
||||
List<Long> preferredCallIds = preferredCalls.stream()
|
||||
.map(BeneficiaryPreferredCallEntity::getCallId)
|
||||
.collect(Collectors.toList());
|
||||
calls = callRepository.findByIdInAndStatusIn(preferredCallIds, callStatusList);
|
||||
} else {
|
||||
calls = callRepository.findByStatusInAndHubId(callStatusList, user.getHub().getId());
|
||||
}
|
||||
List<Long> callIds = calls.stream().map(CallEntity::getId).collect(Collectors.toList());
|
||||
Map<String, BeneficiaryPreferredCallEntity> preferredCallsMap =
|
||||
getBeneficiaryPreferredCallsForUser(request,user, callIds, companyId);
|
||||
|
||||
Reference in New Issue
Block a user