From 3309434ce2f3be9d0a35b71f54dc70511def6ed7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E1=84=8B=E1=85=A1=E1=86=AB=E1=84=82=E1=85=A1=E1=84=8B?= =?UTF-8?q?=E1=85=A7=E1=86=BC?= Date: Wed, 5 Jun 2024 23:07:28 +0900 Subject: [PATCH 1/4] =?UTF-8?q?refactor:=20=ED=99=98=EC=9C=A8=20=EC=95=8C?= =?UTF-8?q?=EB=A6=BC=20api=20=EC=97=B0=EB=8F=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../common/firebase/FirebaseFCMService.java | 13 ++++++------- .../exchangeRate/service/ExchangeService.java | 4 ++-- 2 files changed, 8 insertions(+), 9 deletions(-) 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..f46893c 100644 --- a/src/main/java/com/hanaro/triptogether/exchangeRate/service/ExchangeService.java +++ b/src/main/java/com/hanaro/triptogether/exchangeRate/service/ExchangeService.java @@ -39,7 +39,7 @@ public class ExchangeService { private final ExchangeRateRepository exchangeRateRepository; private final ExchangeUtils exchangeUtils; - private FirebaseFCMService firebaseFCMService; + private final FirebaseFCMService firebaseFCMService; public ExchangeRateInfoResponseDto getExchangeRate(){ @@ -94,7 +94,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); From ae31def7cf83eeaabcb4cb43ff7fdb4043b2a03a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E1=84=8B=E1=85=A1=E1=86=AB=E1=84=82=E1=85=A1=E1=84=8B?= =?UTF-8?q?=E1=85=A7=E1=86=BC?= Date: Wed, 5 Jun 2024 23:07:28 +0900 Subject: [PATCH 2/4] =?UTF-8?q?refactor:=20=ED=99=98=EC=9C=A8=20=EC=95=8C?= =?UTF-8?q?=EB=A6=BC=20api=20=EC=97=B0=EB=8F=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../common/firebase/FirebaseFCMService.java | 13 ++++++------- .../exchangeRate/service/ExchangeService.java | 4 ++-- 2 files changed, 8 insertions(+), 9 deletions(-) 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..f46893c 100644 --- a/src/main/java/com/hanaro/triptogether/exchangeRate/service/ExchangeService.java +++ b/src/main/java/com/hanaro/triptogether/exchangeRate/service/ExchangeService.java @@ -39,7 +39,7 @@ public class ExchangeService { private final ExchangeRateRepository exchangeRateRepository; private final ExchangeUtils exchangeUtils; - private FirebaseFCMService firebaseFCMService; + private final FirebaseFCMService firebaseFCMService; public ExchangeRateInfoResponseDto getExchangeRate(){ @@ -94,7 +94,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); From 6773eb6bd4dcd4a6d2e31dfea5f68d9e686cf028 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E1=84=8B=E1=85=A1=E1=86=AB=E1=84=82=E1=85=A1=E1=84=8B?= =?UTF-8?q?=E1=85=A7=E1=86=BC?= Date: Wed, 5 Jun 2024 23:29:23 +0900 Subject: [PATCH 3/4] =?UTF-8?q?refactor:=20=EC=95=88=EC=93=B0=EB=8A=94=20?= =?UTF-8?q?=EC=BD=94=EB=93=9C=20=EC=A0=95=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../exchangeRate/service/ExchangeService.java | 2 -- .../service/NotificationService.java | 32 ------------------- 2 files changed, 34 deletions(-) delete mode 100644 src/main/java/com/hanaro/triptogether/exchangeRate/service/NotificationService.java 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 f46893c..4bfc8fe 100644 --- a/src/main/java/com/hanaro/triptogether/exchangeRate/service/ExchangeService.java +++ b/src/main/java/com/hanaro/triptogether/exchangeRate/service/ExchangeService.java @@ -16,7 +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; @@ -34,7 +33,6 @@ public class ExchangeService { private final ExchangeRateAlarmRepository exchangeRateAlarmRepository; - private final TeamRepository teamRepository; private final MemberRepository memberRepository; private final ExchangeRateRepository exchangeRateRepository; 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); - - } - } - -} From 2aaa30a0066ef984cb9b1fc089b4c7d0c177834c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E1=84=8B=E1=85=A1=E1=86=AB=E1=84=82=E1=85=A1=E1=84=8B?= =?UTF-8?q?=E1=85=A7=E1=86=BC?= Date: Wed, 5 Jun 2024 23:35:04 +0900 Subject: [PATCH 4/4] =?UTF-8?q?refactor:=20=EC=95=88=EC=93=B0=EB=8A=94=20i?= =?UTF-8?q?mport=EB=AC=B8=20=EC=A0=9C=EA=B1=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../triptogether/exchangeRate/service/ExchangeService.java | 1 - 1 file changed, 1 deletion(-) 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 4bfc8fe..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,7 +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.TeamRepository; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional;