diff --git a/backend/src/main/java/com/worlabel/global/config/FCMConfig.java b/backend/src/main/java/com/worlabel/global/config/FCMConfig.java index fe3d47e..d99066d 100644 --- a/backend/src/main/java/com/worlabel/global/config/FCMConfig.java +++ b/backend/src/main/java/com/worlabel/global/config/FCMConfig.java @@ -40,12 +40,10 @@ public class FCMConfig { FirebaseApp firebaseApp = FirebaseApp.getApps().isEmpty() ? FirebaseApp.initializeApp(options) : FirebaseApp.getInstance(); - log.debug("firebase 불러오기 성공"); // 설정된 FirebaseApp 연결된 FirebaseMessaging 인스턴스를 반환 return FirebaseMessaging.getInstance(firebaseApp); } catch (IOException e) { throw new CustomException(ErrorCode.SERVER_ERROR, "Firebase Key 불러오기 실패 "); } } - } diff --git a/backend/src/main/java/com/worlabel/global/service/FCMService.java b/backend/src/main/java/com/worlabel/global/service/FCMService.java new file mode 100644 index 0000000..ccac82b --- /dev/null +++ b/backend/src/main/java/com/worlabel/global/service/FCMService.java @@ -0,0 +1,29 @@ +package com.worlabel.global.service; + +import com.google.firebase.messaging.FirebaseMessaging; +import com.google.firebase.messaging.Message; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.springframework.stereotype.Service; + +@Slf4j +@Service +@RequiredArgsConstructor +public class FCMService { + + private final FirebaseMessaging firebaseMessaging; + + private void sendNotification(String targetToken, String title, String body){ + Message message = Message.builder() + .setToken(targetToken) + .putData("title",title) + .putData("body",body) + .build(); + try { + log.debug("FCM 알림 전송 {}", message); + firebaseMessaging.sendAsync(message); + } catch (Exception e) { + log.error("FCM 전송 오류 ", e); + } + } +}