Skip to content

Commit

Permalink
refactor: ReminderNotificationService 서비스 로직 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
olivejua committed Oct 7, 2024
1 parent c5fc51c commit 14b59f0
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package com.taskbuddy.core.service;

import com.taskbuddy.core.domain.ReminderSettings;
import com.taskbuddy.core.domain.Task;
import com.taskbuddy.core.domain.User;
import com.taskbuddy.core.service.port.ClockHolder;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;

@RequiredArgsConstructor
@Service
public class ReminderNotificationService {
private final ReminderSettingsService reminderSettingsService;
private final UserService userService;
// private final NotificationService notificationService;
private final ClockHolder clockHolder;

public void sendNotification(Task task) {
User user = task.getUser();

// 1. 유저가 리마인드 알림설정이 켜져있는지 확인
if (!user.isReminderEnabled()) {
return; // 유저가 알림을 원하지 않으면 스킵
}

// 2. Task의 리마인드 설정이 켜져 있는지 확인
if (!task.isReminderEnabled()) {
return; // Task의 리마인드 설정이 꺼져 있으면 스킵
}

// 3. 리마인더주기에 맞는지 확인
ReminderSettings reminderSettings = reminderSettingsService.getByTaskId(task.getId());

// 마지막으로 알림을 보낼 시간이 리마인드 주기 이상일 경우에만 알림 전송
if (!reminderSettings.isReminderDue(clockHolder)) {
return; // 아직 리마인드 주기가 지나지 않았으므로 스킵
}

// 4. 유저가 현재 접속 중인지 확인 (접속 중이 아니면 리마인드)
if (!userService.isUserLoggedIn(user)) {
//리마인더 알림 전송
// notificationService.sendReminder(user, task);
reminderSettingsService.updateLastSentTime(reminderSettings, LocalDateTime.now());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ public ReminderSettings getByTaskId(Long taskId) {
.orElseThrow(() -> new IllegalArgumentException("Task Settings with given task id does not exist."));
}


public void initialize(Task task, Duration reminderInterval) {
if (!task.isReminderEnabled()) {
return;
Expand Down

0 comments on commit 14b59f0

Please sign in to comment.