Skip to content

Commit

Permalink
test: 알람 테스트2
Browse files Browse the repository at this point in the history
  • Loading branch information
AlmondBreez3 committed Feb 6, 2024
1 parent 024a584 commit da4c4c4
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import com.example.domains.user.repository.UserRepository;
import com.example.domains.userscreening.adaptor.UserScreeningAdaptor;
import com.example.domains.userscreening.entity.UserScreening;
import com.example.fcm.adaptor.FcmTokenAdaptor;
import com.example.fcm.entity.FCMToken;
import com.example.fcm.repository.FcmRepository;
import com.example.fcm.request.NotificationRequest;
Expand All @@ -28,6 +29,7 @@ public class ScheduleService {
private final ScreeningAdaptor screeningAdaptor;
private final UserRepository userRepository;
private final FcmRepository fcmRepository;
private final FcmTokenAdaptor fcmTokenAdaptor;

private static final String NOTIFICATION_TITLE = "상영회 하루 전 알림";
// @Scheduled(cron = "0 0/1 * * * *")
Expand Down Expand Up @@ -97,13 +99,15 @@ private void notifyReservation() {
// 오늘이 screeningStartDate의 하루 전인 경우 해당 Screening을 가져옴
if (screeningStartDate.toLocalDate().isEqual(ChronoLocalDate.from(reservationTime))) {
Long userId = userScreening.getUser().getId();
NotificationRequest notificationRequests = new NotificationRequest(userScreening.getScreening(), userId, userScreening.getScreening().getTitle());
sendNotifications(notificationRequests);
if (checkFcmExists(userId)) {
NotificationRequest notificationRequests = new NotificationRequest(userScreening.getScreening(), userId, userScreening.getScreening().getTitle());
sendNotifications(notificationRequests);
}
}
}
}

@Scheduled(cron = "0 11/15 19 * * *")
@Scheduled(cron = "0 20 19 * * *")
private void notifyTestReservation() {
LocalDateTime now = LocalDateTime.now().withSecond(0).withNano(0);
LocalDateTime reservationTime = now.plusDays(1);
Expand All @@ -121,12 +125,22 @@ private void notifyTestReservation() {
// 오늘이 screeningStartDate의 하루 전인 경우 해당 Screening을 가져옴
if (screeningStartDate.toLocalDate().isEqual(ChronoLocalDate.from(reservationTime))) {
Long userId = userScreening.getUser().getId();
NotificationRequest notificationRequests = new NotificationRequest(userScreening.getScreening(), userId, userScreening.getScreening().getTitle());
sendNotifications(notificationRequests);
if (checkFcmExists(userId)) {
NotificationRequest notificationRequests = new NotificationRequest(userScreening.getScreening(), userId, userScreening.getScreening().getTitle());
sendNotifications(notificationRequests);
}
}
}
}

private boolean checkFcmExists(Long userId) {
if (fcmTokenAdaptor.findByUserId(userId)){
return true;
} else {
return false;
}
}


private void sendNotifications(NotificationRequest requests) {
// FCM을 사용하여 알림을 보내는 로직
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,8 @@ public class FcmTokenAdaptor {
public void execute(Long userId) {
fcmRepository.deleteByUserId(userId);
}

public boolean findByUserId(Long userId) {
return fcmRepository.existsById(userId);
}
}

0 comments on commit da4c4c4

Please sign in to comment.