diff --git a/src/main/java/com/hanaro/triptogether/common/firebase/FirebaseFCMService.java b/src/main/java/com/hanaro/triptogether/common/firebase/FirebaseFCMService.java index aff0fc0..0f2bd87 100644 --- a/src/main/java/com/hanaro/triptogether/common/firebase/FirebaseFCMService.java +++ b/src/main/java/com/hanaro/triptogether/common/firebase/FirebaseFCMService.java @@ -5,10 +5,7 @@ import com.google.auth.oauth2.GoogleCredentials; import com.google.firebase.FirebaseApp; import com.google.firebase.FirebaseOptions; -import com.google.firebase.messaging.BatchResponse; -import com.google.firebase.messaging.FirebaseMessaging; -import com.google.firebase.messaging.FirebaseMessagingException; -import com.google.firebase.messaging.MulticastMessage; +import com.google.firebase.messaging.*; import com.hanaro.triptogether.common.response.BaseResponse; import com.hanaro.triptogether.common.response.ResponseStatus; import com.hanaro.triptogether.dues.dto.request.DuesAlarmRequestDto; @@ -76,6 +73,7 @@ public void sendMessageTo(FcmSendDto fcmSendDto) throws IOException { private String makeMessage(FcmSendDto fcmSendDto) throws JsonProcessingException { ObjectMapper om = new ObjectMapper(); + FcmMessageDto fcmMessageDto = FcmMessageDto .builder() .message(FcmMessageDto.Message.builder() @@ -135,9 +133,10 @@ public BaseResponse notificationAlarm(String title, String body, DuesAlarmReques } MulticastMessage message = MulticastMessage.builder() - .putData("fcm_type","NOTIFICATION") - .putData("title",title) - .putData("body",body) + .setNotification(Notification.builder() + .setTitle(title) + .setBody("회비 "+body+" 원을 요청하였습니다.") + .build()) .addAllTokens(tokenList) .build(); diff --git a/src/main/java/com/hanaro/triptogether/exchangeRate/service/ExchangeService.java b/src/main/java/com/hanaro/triptogether/exchangeRate/service/ExchangeService.java index 28e56a2..15221a7 100644 --- a/src/main/java/com/hanaro/triptogether/exchangeRate/service/ExchangeService.java +++ b/src/main/java/com/hanaro/triptogether/exchangeRate/service/ExchangeService.java @@ -16,8 +16,6 @@ import com.hanaro.triptogether.exchangeRate.utils.ExchangeUtils; import com.hanaro.triptogether.member.domain.Member; import com.hanaro.triptogether.member.domain.MemberRepository; -import com.hanaro.triptogether.team.domain.Team; -import com.hanaro.triptogether.team.domain.TeamRepository; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -34,12 +32,11 @@ public class ExchangeService { private final ExchangeRateAlarmRepository exchangeRateAlarmRepository; - private final TeamRepository teamRepository; private final MemberRepository memberRepository; private final ExchangeRateRepository exchangeRateRepository; private final ExchangeUtils exchangeUtils; - private FirebaseFCMService firebaseFCMService; + private final FirebaseFCMService firebaseFCMService; public ExchangeRateInfoResponseDto getExchangeRate(){ @@ -94,7 +91,7 @@ public void checkNotifyAlarms() throws IOException { } if (notify) { - firebaseFCMService.sendMessageTo(FcmSendDto.builder().token(alarm.getFcmToken()).title("환율 알림").body("설정한 환율 조건에 도달했습니다.").build()); + firebaseFCMService.sendMessageTo(FcmSendDto.builder().token(alarm.getFcmToken()).title("환율 알림").body("환율이 "+alarm.getCurRate()+" 에 도달했어요~!!.").build()); alarm.setNotified(true); exchangeRateAlarmRepository.save(alarm); diff --git a/src/main/java/com/hanaro/triptogether/exchangeRate/service/NotificationService.java b/src/main/java/com/hanaro/triptogether/exchangeRate/service/NotificationService.java deleted file mode 100644 index 59f3ab1..0000000 --- a/src/main/java/com/hanaro/triptogether/exchangeRate/service/NotificationService.java +++ /dev/null @@ -1,32 +0,0 @@ -package com.hanaro.triptogether.exchangeRate.service; - -import com.google.firebase.messaging.FirebaseMessaging; -import com.google.firebase.messaging.FirebaseMessagingException; -import com.google.firebase.messaging.Message; -import com.google.firebase.messaging.Notification; -import com.hanaro.triptogether.exchangeRate.dto.request.FcmSendDto; -import lombok.RequiredArgsConstructor; -import org.springframework.stereotype.Service; - -@Service -@RequiredArgsConstructor -public class NotificationService { - - - // 단일 전송 - public void sendMessageByToken(FcmSendDto fcmSendDto) { - try { - FirebaseMessaging.getInstance().send(Message.builder() - .setNotification(Notification.builder() - .setTitle(fcmSendDto.getTitle()) - .setBody(fcmSendDto.getBody()) - .build()) - .setToken(fcmSendDto.getToken()) - .build()); - } catch (FirebaseMessagingException e) { - System.out.println("Firebase error sending: {}"+ e); - - } - } - -}