Skip to content

Commit

Permalink
Merge pull request #459 from this-Aditya/task-completion
Browse files Browse the repository at this point in the history
Deleting associated notifications and reminders after task is completed
  • Loading branch information
mpgxvii authored Apr 15, 2024
2 parents 8325222 + 5981a75 commit 15e217b
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,12 @@ public interface NotificationRepository extends JpaRepository<Notification, Long

List<Notification> findByUserIdAndTaskId(Long userId, Long taskId);

List<Notification> findByTaskId(Long id);

void deleteByUserId(Long userId);

void deleteByTaskId(Long taskId);

void deleteByUserIdAndTaskId(Long userId, Long taskId);

boolean existsByUserIdAndSourceIdAndScheduledTimeAndTitleAndBodyAndTypeAndTtlSeconds(
Expand All @@ -63,6 +67,8 @@ Optional<Notification> findByUserIdAndSourceIdAndScheduledTimeAndTitleAndBodyAnd

boolean existsById(@NotNull Long id);

boolean existsByTaskId(Long taskId);

void deleteByFcmMessageId(String fcmMessageId);

void deleteByIdAndUserId(Long id, Long userId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import org.radarbase.appserver.dto.fcm.FcmNotifications;
import org.radarbase.appserver.entity.Notification;
import org.radarbase.appserver.entity.Project;
import org.radarbase.appserver.entity.Task;
import org.radarbase.appserver.entity.User;
import org.radarbase.appserver.event.state.MessageState;
import org.radarbase.appserver.event.state.dto.NotificationStateEventDto;
Expand Down Expand Up @@ -368,6 +369,16 @@ public void removeNotificationsForUserUsingFcmToken(String fcmToken) {
});
}

@Transactional
public void deleteNotificationsByTaskId(Task task) {
Long taskId = task.getId();
if(notificationRepository.existsByTaskId(taskId)) {
List<Notification> notifications = notificationRepository.findByTaskId(taskId);
schedulerService.deleteScheduledMultiple(notifications);
notificationRepository.deleteByTaskId(taskId);
}
}

@Transactional
public FcmNotifications addNotifications(
FcmNotifications notificationDtos, String subjectId, String projectId, boolean schedule) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ public class TaskStateEventService {

private final transient TaskStateEventRepository taskStateEventRepository;
private final transient TaskService taskService;
private final transient FcmNotificationService notificationService;

private final transient ApplicationEventPublisher taskApplicationEventPublisher;
private final transient ObjectMapper objectMapper;
Expand All @@ -65,10 +66,12 @@ public class TaskStateEventService {
public TaskStateEventService(
TaskStateEventRepository taskStateEventRepository,
TaskService taskService,
FcmNotificationService notificationService,
ApplicationEventPublisher taskApplicationEventPublisher,
ObjectMapper objectMapper) {
this.taskStateEventRepository = taskStateEventRepository;
this.taskService = taskService;
this.notificationService = notificationService;
this.taskApplicationEventPublisher = taskApplicationEventPublisher;
this.objectMapper = objectMapper;
}
Expand All @@ -77,6 +80,9 @@ public TaskStateEventService(
public void addTaskStateEvent(TaskStateEvent taskStateEvent) {
taskStateEventRepository.save(taskStateEvent);
taskService.updateTaskStatus(taskStateEvent.getTask(), taskStateEvent.getState());
if (taskStateEvent.getState().equals(TaskState.COMPLETED)) {
notificationService.deleteNotificationsByTaskId(taskStateEvent.getTask());
}
}

@Transactional(readOnly = true)
Expand Down

0 comments on commit 15e217b

Please sign in to comment.