From dfe4ae9b5ae17c5ea81b5f21f75d88efe21bf776 Mon Sep 17 00:00:00 2001 From: apptie Date: Sat, 16 Sep 2023 21:52:02 +0900 Subject: [PATCH 1/2] =?UTF-8?q?refactor:=20production=20=ED=99=98=EA=B2=BD?= =?UTF-8?q?=EC=97=90=EC=84=9C=EC=9D=98=20FCM=20Configuration=20=ED=81=B4?= =?UTF-8?q?=EB=9E=98=EC=8A=A4=20=EB=84=A4=EC=9D=B4=EB=B0=8D=20=EB=B3=80?= =?UTF-8?q?=EA=B2=BD=20=EB=B0=8F=20profile=20=EC=84=A4=EC=A0=95=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../fcm/{FcmConfiguration.java => ProdFcmConfiguration.java} | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) rename backend/ddang/src/main/java/com/ddang/ddang/configuration/fcm/{FcmConfiguration.java => ProdFcmConfiguration.java} (96%) diff --git a/backend/ddang/src/main/java/com/ddang/ddang/configuration/fcm/FcmConfiguration.java b/backend/ddang/src/main/java/com/ddang/ddang/configuration/fcm/ProdFcmConfiguration.java similarity index 96% rename from backend/ddang/src/main/java/com/ddang/ddang/configuration/fcm/FcmConfiguration.java rename to backend/ddang/src/main/java/com/ddang/ddang/configuration/fcm/ProdFcmConfiguration.java index be95af35c..ac0848a4b 100644 --- a/backend/ddang/src/main/java/com/ddang/ddang/configuration/fcm/FcmConfiguration.java +++ b/backend/ddang/src/main/java/com/ddang/ddang/configuration/fcm/ProdFcmConfiguration.java @@ -16,8 +16,8 @@ import org.springframework.context.annotation.Profile; @Configuration -@Profile("!test") -public class FcmConfiguration { +@Profile("!test && !local") +public class ProdFcmConfiguration { @Value("${fcm.key.path}") private String FCM_PRIVATE_KEY_PATH; From 8fa2b957e910dc85f563237662a9c287c932dc8d Mon Sep 17 00:00:00 2001 From: apptie Date: Sat, 16 Sep 2023 21:53:04 +0900 Subject: [PATCH 2/2] =?UTF-8?q?refactor:=20local=20=ED=99=98=EA=B2=BD?= =?UTF-8?q?=EC=97=90=EC=84=9C=EC=9D=98=20FCM=20Configuration=20=ED=81=B4?= =?UTF-8?q?=EB=9E=98=EC=8A=A4=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../fcm/LocalFcmConfiguration.java | 40 +++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 backend/ddang/src/main/java/com/ddang/ddang/configuration/fcm/LocalFcmConfiguration.java diff --git a/backend/ddang/src/main/java/com/ddang/ddang/configuration/fcm/LocalFcmConfiguration.java b/backend/ddang/src/main/java/com/ddang/ddang/configuration/fcm/LocalFcmConfiguration.java new file mode 100644 index 000000000..d2bf7a58a --- /dev/null +++ b/backend/ddang/src/main/java/com/ddang/ddang/configuration/fcm/LocalFcmConfiguration.java @@ -0,0 +1,40 @@ +package com.ddang.ddang.configuration.fcm; + +import com.google.firebase.FirebaseApp; +import com.google.firebase.FirebaseOptions; +import com.google.firebase.messaging.FirebaseMessaging; +import java.util.List; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.context.annotation.Profile; + +@Configuration +@Profile("local") +public class LocalFcmConfiguration { + + @Bean + public FirebaseMessaging firebaseMessaging() { + final FirebaseApp firebaseApps = findFirebaseApps(); + + return FirebaseMessaging.getInstance(firebaseApps); + } + + private FirebaseApp findFirebaseApps() { + final List apps = FirebaseApp.getApps(); + + if (!apps.isEmpty()) { + for (final FirebaseApp app : apps) { + if (FirebaseApp.DEFAULT_APP_NAME.equals(app.getName())) { + return app; + } + } + } + + final FirebaseOptions options = FirebaseOptions.builder() + .setCredentials(new MockGoogleCredentials("test-token")) + .setProjectId("test-project") + .build(); + + return FirebaseApp.initializeApp(options); + } +}