Preferred call changes

This commit is contained in:
harish
2024-11-13 13:08:48 +05:30
parent a62d704124
commit 33332b01c8
8 changed files with 49 additions and 19 deletions

View File

@@ -77,17 +77,18 @@ public class BeneficiaryPreferredCallDao {
// }
public void deleteBeneficiaryPreferredCallById(HttpServletRequest request, Long id) {
log.info("Deleting beneficiary preferred call with ID: {}", id);
log.info("Soft deleting beneficiary preferred call with ID: {}", id);
BeneficiaryPreferredCallEntity entity = validateBeneficiaryPreferredCall(id);
validator.validateUserId(request, entity.getUserId());
beneficiaryPreferredCallRepository.deleteById(id);
log.info("Beneficiary preferred call deleted with ID: {}", id);
entity.setIsDeleted(true);
beneficiaryPreferredCallRepository.save(entity);
log.info("Beneficiary preferred call soft deleted with ID: {}", id);
}
public List<BeneficiaryPreferredCallResponseBean> getAllBeneficiaryPreferredCalls(HttpServletRequest request) {
UserEntity userEntity = validator.validateUser(request);
log.info("Fetching all beneficiary preferred calls");
List<BeneficiaryPreferredCallResponseBean> calls = beneficiaryPreferredCallRepository.findByUserId(userEntity.getId())
List<BeneficiaryPreferredCallResponseBean> calls = beneficiaryPreferredCallRepository.findByUserIdAndIsDeletedFalse(userEntity.getId())
.stream()
.map(this::convertEntityToResponse)
.collect(Collectors.toList());
@@ -97,7 +98,7 @@ public class BeneficiaryPreferredCallDao {
private BeneficiaryPreferredCallEntity validateBeneficiaryPreferredCall(Long id) {
log.info("Validating beneficiary preferred call with ID: {}", id);
return beneficiaryPreferredCallRepository.findById(id)
return beneficiaryPreferredCallRepository.findByIdAndIsDeletedFalse(id)
.orElseThrow(() -> new ResourceNotFoundException(Status.NOT_FOUND, Translator.toLocale(GepafinConstant.BENEFICIARY_CALL_NOT_FOUND)));
}
@@ -123,7 +124,7 @@ public class BeneficiaryPreferredCallDao {
}
public List<BeneficiaryPreferredCallResponseBean> getBeneficiaryPreferredCallByUserId(UserEntity userEntity, Long companyId) {
List<BeneficiaryPreferredCallEntity> calls = beneficiaryPreferredCallRepository.findByUserIdAndCompanyId(userEntity.getId(), companyId);
List<BeneficiaryPreferredCallEntity> calls = beneficiaryPreferredCallRepository.findByUserIdAndCompanyIdAndIsDeletedFalse(userEntity.getId(), companyId);
return calls.stream()
.map(this::convertEntityToResponse)
.collect(Collectors.toList());

View File

@@ -425,10 +425,22 @@ public class CallDao {
Translator.toLocale(GepafinConstant.CALL_NOT_FOUND)));
}
public CallResponse getCallById(CallEntity callEntity) {
return getCallResponseBean(callEntity);
public CallResponse getCallById(UserEntity user, CallEntity callEntity) {
Long userId = user.getId();
Long callId = callEntity.getId();
BeneficiaryPreferredCallEntity preferredCall = beneficiaryPreferredCallRepository
.findByUserIdAndCallIdInAndIsDeletedFalse(userId, List.of(callId))
.stream()
.findFirst()
.orElse(null);
CallResponse callResponse = getCallResponseBean(callEntity);
callResponse.setPreferredCallId(preferredCall != null ? preferredCall.getId() : null);
return callResponse;
}
public CallResponse createCallStep2(CallEntity callEntity, CreateCallRequestStep2 createCallRequest, UserEntity user) {
validateUpdate(callEntity);
setIfUpdated(callEntity::getThreshold, callEntity::setThreshold, createCallRequest.getThreshold());
@@ -648,6 +660,7 @@ public class CallDao {
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<Long> callIds = calls.stream().map(CallEntity::getId).collect(Collectors.toList());
@@ -657,16 +670,19 @@ public class CallDao {
.map(call -> {
CallDetailsResponseBean responseBean = convertToCallDetailsResponseBean(call);
String key = user.getId() + "_" + call.getId();
boolean isPreferred = preferredCallsMap.containsKey(key);
responseBean.setPreferred(isPreferred);
BeneficiaryPreferredCallEntity preferredCall = preferredCallsMap.get(key);
Long preferredId = (preferredCall != null && !preferredCall.getIsDeleted()) ? preferredCall.getId() : null;
responseBean.setPreferredCallId(preferredId);
return responseBean;
})
.collect(Collectors.toList());
}
public Map<String, BeneficiaryPreferredCallEntity> getBeneficiaryPreferredCallsForUser(UserEntity user, List<Long> callIds) {
public Map<String, BeneficiaryPreferredCallEntity> getBeneficiaryPreferredCallsForUser(UserEntity user, List<Long> callIds) {
List<BeneficiaryPreferredCallEntity> beneficiaryPreferredCalls = beneficiaryPreferredCallRepository
.findByUserIdAndCallIdIn(user.getId(), callIds);
.findByUserIdAndCallIdInAndIsDeletedFalse(user.getId(), callIds);
return beneficiaryPreferredCalls.stream()
.collect(Collectors.toMap(

View File

@@ -34,4 +34,6 @@ public class BeneficiaryPreferredCallEntity extends BaseEntity{
@Column(name = "STATUS", length = 255)
private String status;
@Column(name="IS_DELETED")
private Boolean isDeleted;
}

View File

@@ -53,5 +53,6 @@ public class CallDetailsResponseBean {
private LocalDateTime createdDate;
private LocalDateTime updatedDate;
private Boolean preferred;
private Long preferredCallId;
}

View File

@@ -73,6 +73,7 @@ public class CallResponse {
private String currentStep;
private Long preferredCallId;
}

View File

@@ -6,15 +6,17 @@ import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;
import java.util.List;
import java.util.Optional;
@Repository
public interface BeneficiaryPreferredCallRepository extends JpaRepository<BeneficiaryPreferredCallEntity, Long> {
List<BeneficiaryPreferredCallEntity> findByBeneficiaryId(Long beneficiaryId);
List<BeneficiaryPreferredCallEntity> findByUserId(Long userId);
List<BeneficiaryPreferredCallEntity> findByBeneficiaryIdAndIsDeletedFalse(Long beneficiaryId);
List<BeneficiaryPreferredCallEntity> findByUserIdAndIsDeletedFalse(Long userId);
@Query("SELECT preferredCall FROM BeneficiaryPreferredCallEntity preferredCall where preferredCall.userId=:userId AND (:companyId is null OR preferredCall.companyId=:companyId)")
List<BeneficiaryPreferredCallEntity> findByUserIdAndCompanyId(@Param("userId") Long userId, @Param("companyId") Long companyId);
List<BeneficiaryPreferredCallEntity> findByUserIdAndCompanyIdAndIsDeletedFalse(@Param("userId") Long userId, @Param("companyId") Long companyId);
List<BeneficiaryPreferredCallEntity> findByBeneficiaryIdAndCompanyId(Long beneficiaryId,Long companyId);
@Query("SELECT preferredCall FROM BeneficiaryPreferredCallEntity preferredCall WHERE preferredCall.userId = :userId AND preferredCall.callId IN :callIds")
List<BeneficiaryPreferredCallEntity> findByUserIdAndCallIdIn(@Param("userId") Long userId, @Param("callIds") List<Long> callIds);
public List<BeneficiaryPreferredCallEntity> findByUserIdAndCallIdInAndIsDeletedFalse(Long userId, List<Long> callIds);
Optional<BeneficiaryPreferredCallEntity> findByIdAndIsDeletedFalse(Long id);
}

View File

@@ -57,7 +57,7 @@ public class CallServiceImpl implements CallService {
public CallResponse getCallById(HttpServletRequest request, Long callId) {
UserEntity user = validator.validateUser(request);
CallEntity call = validator.validateUserWithCall(user, callId);
return callDao.getCallById(call);
return callDao.getCallById(user,call);
}
@Override

View File

@@ -1720,4 +1720,11 @@
<sqlFile dbms="postgresql"
path="db/dump/update_system_email_template_for_notification_mail_05_11_2024_4.sql"/>
</changeSet>
<changeSet id="13-11-2024_1" author="Harish Bagora">
<addColumn tableName="beneficiary_preferred_call">
<column name="is_deleted" type="BOOLEAN" defaultValueBoolean="false">
<constraints nullable="false"/>
</column>
</addColumn>
</changeSet>
</databaseChangeLog>