Updated code.
This commit is contained in:
@@ -119,9 +119,6 @@ public class CallDao {
|
|||||||
@Autowired
|
@Autowired
|
||||||
private NotificationTypeRepository notificationTypeRepository;
|
private NotificationTypeRepository notificationTypeRepository;
|
||||||
|
|
||||||
@Autowired
|
|
||||||
private UserWithCompanyRepository userWithCompanyRepository;
|
|
||||||
|
|
||||||
public CallResponse createCallStep1(CreateCallRequestStep1 createCallRequest, UserEntity userEntity) {
|
public CallResponse createCallStep1(CreateCallRequestStep1 createCallRequest, UserEntity userEntity) {
|
||||||
createCallRequest.setRegionId(userEntity.getRoleEntity().getRegion().getId());
|
createCallRequest.setRegionId(userEntity.getRoleEntity().getRegion().getId());
|
||||||
CallEntity callEntity = convertToCallEntity(createCallRequest, userEntity);
|
CallEntity callEntity = convertToCallEntity(createCallRequest, userEntity);
|
||||||
@@ -848,9 +845,7 @@ public class CallDao {
|
|||||||
Map<String, String> placeholders = new HashMap<>();
|
Map<String, String> placeholders = new HashMap<>();
|
||||||
placeholders.put("{{call_name}}", callEntity.getName());
|
placeholders.put("{{call_name}}", callEntity.getName());
|
||||||
userIds.forEach(userId -> {
|
userIds.forEach(userId -> {
|
||||||
NotificationReq notificationReq = createNotificationReq(NotificationTypeEnum.CALL_CREATED.getValue(), placeholders, userId);
|
NotificationReq notificationReq = notificationDao.createNotificationReq(NotificationTypeEnum.CALL_CREATED.getValue(), placeholders, userId);
|
||||||
List<Long> companyIds = userWithCompanyRepository.findActiveCompanyIdsByUserId(notificationReq.getUserId());
|
|
||||||
notificationReq.setCompanyIds(companyIds);
|
|
||||||
notificationDao.sendNotification(notificationReq);
|
notificationDao.sendNotification(notificationReq);
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -860,18 +855,6 @@ public class CallDao {
|
|||||||
return convertToCallResponseBean(callEntity);
|
return convertToCallResponseBean(callEntity);
|
||||||
}
|
}
|
||||||
|
|
||||||
public NotificationReq createNotificationReq(String notificationType, Map<String, String> placeholders, Long userId) {
|
|
||||||
// Create NotificationReq object
|
|
||||||
NotificationReq notificationReq = new NotificationReq();
|
|
||||||
NotificationTypeEntity notificationTypeEntity = notificationTypeRepository.findByNotificationNameAndIsDeletedFalse(notificationType);
|
|
||||||
notificationReq.setNotificationType(notificationType);
|
|
||||||
String message = Utils.replacePlaceholders(notificationTypeEntity.getJsonTemplate(), placeholders);
|
|
||||||
notificationReq.setMessage(message);
|
|
||||||
notificationReq.setUserId(userId);
|
|
||||||
return notificationReq;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
private void validateStatusChange(CallStatusEnum currentStatus, CallStatusEnum newStatus) {
|
private void validateStatusChange(CallStatusEnum currentStatus, CallStatusEnum newStatus) {
|
||||||
if (currentStatus == newStatus) {
|
if (currentStatus == newStatus) {
|
||||||
throw new CustomValidationException(Status.VALIDATION_ERROR,
|
throw new CustomValidationException(Status.VALIDATION_ERROR,
|
||||||
|
|||||||
@@ -3,16 +3,19 @@ package net.gepafin.tendermanagement.dao;
|
|||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import net.gepafin.tendermanagement.constants.GepafinConstant;
|
import net.gepafin.tendermanagement.constants.GepafinConstant;
|
||||||
import net.gepafin.tendermanagement.entities.NotificationEntity;
|
import net.gepafin.tendermanagement.entities.NotificationEntity;
|
||||||
|
import net.gepafin.tendermanagement.entities.NotificationTypeEntity;
|
||||||
import net.gepafin.tendermanagement.enums.NotificationEnum;
|
import net.gepafin.tendermanagement.enums.NotificationEnum;
|
||||||
import net.gepafin.tendermanagement.model.request.NotificationReq;
|
import net.gepafin.tendermanagement.model.request.NotificationReq;
|
||||||
import net.gepafin.tendermanagement.repositories.NotificationRepository;
|
import net.gepafin.tendermanagement.repositories.NotificationRepository;
|
||||||
import net.gepafin.tendermanagement.repositories.NotificationTypeRepository;
|
import net.gepafin.tendermanagement.repositories.NotificationTypeRepository;
|
||||||
|
import net.gepafin.tendermanagement.repositories.UserWithCompanyRepository;
|
||||||
import net.gepafin.tendermanagement.util.Utils;
|
import net.gepafin.tendermanagement.util.Utils;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.messaging.simp.SimpMessagingTemplate;
|
import org.springframework.messaging.simp.SimpMessagingTemplate;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
@Component
|
@Component
|
||||||
@Slf4j
|
@Slf4j
|
||||||
@@ -27,6 +30,9 @@ public class NotificationDao {
|
|||||||
@Autowired
|
@Autowired
|
||||||
private NotificationTypeRepository notificationTypeRepository;
|
private NotificationTypeRepository notificationTypeRepository;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private UserWithCompanyRepository userWithCompanyRepository;
|
||||||
|
|
||||||
public NotificationReq sendNotification(NotificationReq notificationReq) {
|
public NotificationReq sendNotification(NotificationReq notificationReq) {
|
||||||
|
|
||||||
// Ensure userId is properly set in notificationReq if not already
|
// Ensure userId is properly set in notificationReq if not already
|
||||||
@@ -94,4 +100,17 @@ public class NotificationDao {
|
|||||||
notificationEntity.setMessage(message);
|
notificationEntity.setMessage(message);
|
||||||
return notificationEntity;
|
return notificationEntity;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public NotificationReq createNotificationReq(String notificationType, Map<String, String> placeholders, Long userId) {
|
||||||
|
// Create NotificationReq object
|
||||||
|
NotificationReq notificationReq = new NotificationReq();
|
||||||
|
List<Long> companyIds = userWithCompanyRepository.findActiveCompanyIdsByUserId(notificationReq.getUserId());
|
||||||
|
notificationReq.setCompanyIds(companyIds);
|
||||||
|
NotificationTypeEntity notificationTypeEntity = notificationTypeRepository.findByNotificationNameAndIsDeletedFalse(notificationType);
|
||||||
|
notificationReq.setNotificationType(notificationType);
|
||||||
|
String message = Utils.replacePlaceholders(notificationTypeEntity.getJsonTemplate(), placeholders);
|
||||||
|
notificationReq.setMessage(message);
|
||||||
|
notificationReq.setUserId(userId);
|
||||||
|
return notificationReq;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user