Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
…into dev
  • Loading branch information
SUMMERLOVE7 committed Feb 22, 2023
2 parents 42c97af + 9cd837c commit 99ae98b
Showing 1 changed file with 14 additions and 10 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.amatta.amatta_server.fcm.service;

import com.amatta.amatta_server.aop.MethodRequiresAuth;
import com.amatta.amatta_server.fcm.dto.TokenRegisterDto;
import com.amatta.amatta_server.fcm.model.FCMToken;
import com.amatta.amatta_server.fcm.repository.DeviceTokenRepository;
Expand All @@ -15,6 +16,7 @@
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
Expand All @@ -28,10 +30,10 @@ public FCMService(DeviceTokenRepository tokenRepository) {
this.tokenRepository = tokenRepository;
}

// @MethodRequiresAuth
@MethodRequiresAuth
public void addToken(TokenRegisterDto tokenRegisterDto) {
// Users user = getUserBySessionId();
tokenRepository.addToken(2, tokenRegisterDto.getToken());
Users user = getUserBySessionId();
tokenRepository.addToken(user.getId(), tokenRegisterDto.getToken());
}

private void sendMessage(List<String> tokens, String title, String body) throws FirebaseMessagingException {
Expand Down Expand Up @@ -80,18 +82,20 @@ public void sendTestMessage(String token) throws FirebaseMessagingException {
FirebaseMessaging.getInstance().send(message);
}

@Scheduled(cron = "*/10 * * * * *")
@Scheduled(cron = "0 0 0/1 * * *")
@Transactional(readOnly = true)
public void scheduleExpirationAlarmMessage() {
System.out.println("expire");
LocalDate now = LocalDate.now();
LocalDateTime now = LocalDateTime.now();
System.out.println(now + " [스케줄러 실행]");
// List<String> tokens = tokenRepository.findTokensByUidsOfGifticonsAboutToExpire(now.plusDays(Gifticon.expirationThresholdDays));
List<FCMToken> tokens = tokenRepository.findAllTokens();
if (!tokens.isEmpty()) {
try {
sendMessage(tokens.get(0).getToken(), "A! matta", "만료 기간이 얼마 남지 않은 기프티콘이 있습니다!!");
} catch (FirebaseMessagingException e) {
e.printStackTrace();
for(FCMToken token : tokens) {
try {
sendMessage(token.getToken(), "A! matta", "만료 기간이 얼마 남지 않은 기프티콘이 있습니다!!");
} catch (FirebaseMessagingException e) {
e.printStackTrace();
}
}
}
}
Expand Down

0 comments on commit 99ae98b

Please sign in to comment.