From bbce7c58304f248cf55fd70d3656cd4bfb8fbdb7 Mon Sep 17 00:00:00 2001 From: gomin0 Date: Tue, 18 Jun 2024 00:33:19 +0900 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20feat:=20gitingore=20=EC=88=98?= =?UTF-8?q?=EC=A0=95=20=20(#131)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 1 + .../firebase/controller/FcmController.java | 27 --------- .../firebase/dto/FCMAlarmRequestDto.java | 7 --- .../exception/FirebaseExceptionHandler.java | 10 ---- .../firebase/service/FcmAlarmService.java | 58 ------------------- 5 files changed, 1 insertion(+), 102 deletions(-) delete mode 100644 src/main/java/com/capstone/BnagFer/domain/firebase/controller/FcmController.java delete mode 100644 src/main/java/com/capstone/BnagFer/domain/firebase/dto/FCMAlarmRequestDto.java delete mode 100644 src/main/java/com/capstone/BnagFer/domain/firebase/exception/FirebaseExceptionHandler.java delete mode 100644 src/main/java/com/capstone/BnagFer/domain/firebase/service/FcmAlarmService.java diff --git a/.gitignore b/.gitignore index 9c7a04ba..980b937f 100644 --- a/.gitignore +++ b/.gitignore @@ -132,6 +132,7 @@ fabric.properties # Package Files # *.jar +!application.jar *.war *.nar *.ear diff --git a/src/main/java/com/capstone/BnagFer/domain/firebase/controller/FcmController.java b/src/main/java/com/capstone/BnagFer/domain/firebase/controller/FcmController.java deleted file mode 100644 index 70c15f1e..00000000 --- a/src/main/java/com/capstone/BnagFer/domain/firebase/controller/FcmController.java +++ /dev/null @@ -1,27 +0,0 @@ -package com.capstone.BnagFer.domain.firebase.controller; - -import com.capstone.BnagFer.domain.firebase.dto.FCMAlarmRequestDto; -import com.capstone.BnagFer.domain.firebase.service.FcmAlarmService; -import com.capstone.BnagFer.global.common.ApiResponse; -import io.swagger.v3.oas.annotations.Operation; -import io.swagger.v3.oas.annotations.tags.Tag; -import jakarta.validation.Valid; -import lombok.RequiredArgsConstructor; -import lombok.extern.slf4j.Slf4j; -import org.springframework.web.bind.annotation.*; - -@Slf4j -@RestController -@RequiredArgsConstructor -@Tag(name = "푸시 알림 API") -@RequestMapping("/fcm") -public class FcmController { - - private final FcmAlarmService fcmAlarmService; - - @Operation(summary = "푸시 알림 보내기", description = "해당 유저에게 FCM 푸시 알림 전송") - @PostMapping("/send/{userId}") - public ApiResponse sendAlarm(@Valid @RequestBody FCMAlarmRequestDto requestDto, @PathVariable Long userId) { - return ApiResponse.onSuccess(fcmAlarmService.sendAlarm(requestDto, userId)); - } -} \ No newline at end of file diff --git a/src/main/java/com/capstone/BnagFer/domain/firebase/dto/FCMAlarmRequestDto.java b/src/main/java/com/capstone/BnagFer/domain/firebase/dto/FCMAlarmRequestDto.java deleted file mode 100644 index 62564730..00000000 --- a/src/main/java/com/capstone/BnagFer/domain/firebase/dto/FCMAlarmRequestDto.java +++ /dev/null @@ -1,7 +0,0 @@ -package com.capstone.BnagFer.domain.firebase.dto; - -public record FCMAlarmRequestDto ( - String title, - String body -) { -} diff --git a/src/main/java/com/capstone/BnagFer/domain/firebase/exception/FirebaseExceptionHandler.java b/src/main/java/com/capstone/BnagFer/domain/firebase/exception/FirebaseExceptionHandler.java deleted file mode 100644 index a3133ade..00000000 --- a/src/main/java/com/capstone/BnagFer/domain/firebase/exception/FirebaseExceptionHandler.java +++ /dev/null @@ -1,10 +0,0 @@ -package com.capstone.BnagFer.domain.firebase.exception; - -import com.capstone.BnagFer.global.common.BaseErrorCode; -import com.capstone.BnagFer.global.common.exception.CustomException; - -public class FirebaseExceptionHandler extends CustomException { - public FirebaseExceptionHandler(BaseErrorCode errorCode) { - super(errorCode); - } -} diff --git a/src/main/java/com/capstone/BnagFer/domain/firebase/service/FcmAlarmService.java b/src/main/java/com/capstone/BnagFer/domain/firebase/service/FcmAlarmService.java deleted file mode 100644 index 160b6c7e..00000000 --- a/src/main/java/com/capstone/BnagFer/domain/firebase/service/FcmAlarmService.java +++ /dev/null @@ -1,58 +0,0 @@ -package com.capstone.BnagFer.domain.firebase.service; - -import com.capstone.BnagFer.domain.accounts.entity.User; -import com.capstone.BnagFer.global.util.RedisUtil; -import com.capstone.BnagFer.domain.accounts.repository.UserJpaRepository; -import com.capstone.BnagFer.domain.firebase.dto.FCMAlarmRequestDto; -import com.capstone.BnagFer.domain.firebase.exception.FirebaseExceptionHandler; -import com.capstone.BnagFer.global.common.ErrorCode; -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 lombok.RequiredArgsConstructor; -import org.springframework.stereotype.Service; - -import java.util.Optional; - - -@RequiredArgsConstructor -@Service -public class FcmAlarmService { - - private final FirebaseMessaging firebaseMessaging; - private final UserJpaRepository userJpaRepository; - private final RedisUtil redisUtil; - - public String sendAlarm(FCMAlarmRequestDto requestDto, Long userId) { - Optional userOptional = userJpaRepository.findById(userId); - - if (userOptional.isPresent()) { - User user = userOptional.get(); - String fcmToken = redisUtil.getFCMToken(user.getEmail()); - if (fcmToken != null) { - Notification notification = Notification.builder() - .setTitle(requestDto.title()) - .setBody(requestDto.body()) - .build(); - - Message message = Message.builder() - .setToken(fcmToken) - .setNotification(notification) - .build(); - - try { - firebaseMessaging.send(message); - return "알림을 성공적으로 전송했습니다. targetUserId = " + userId; - } catch (FirebaseMessagingException e) { - e.printStackTrace(); - throw new FirebaseExceptionHandler(ErrorCode.FIREBASE_MESSAGING_ERROR); - } - } else { - throw new FirebaseExceptionHandler(ErrorCode.FIREBASE_TOKEN_NOT_FOUND); - } - } else { - throw new FirebaseExceptionHandler(ErrorCode.USER_NOT_FOUND); - } - } -}