Skip to content

Commit

Permalink
fix: fcm 및 fcm 테스트 코드 수정 (#88)
Browse files Browse the repository at this point in the history
* refactor: 푸시 알림 에러 정보 상세 출력

* fix: RequestBody -> RequestParam

* fix: PostConstruct로 firebase 초기화

* test: 수정 사항 임시 배포
  • Loading branch information
kimyu0218 authored Nov 5, 2024
1 parent 0305254 commit f55db8a
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public void sendIndividualMessage(final String title, final String body, final S
try {
FirebaseMessaging.getInstance().send(message);
} catch (FirebaseMessagingException e) {
throw new BaseException(ErrorCode.FAILED_TO_SEND_INDIVIDUAL_MESSAGE);
throw new BaseException(ErrorCode.FAILED_TO_SEND_INDIVIDUAL_MESSAGE, e);
}
}

Expand All @@ -36,7 +36,7 @@ public void sendGroupMessage(final String title, final String body, final String
try {
FirebaseMessaging.getInstance().send(message);
} catch (FirebaseMessagingException e) {
throw new BaseException(ErrorCode.FAILED_TO_SEND_GROUP_MESSAGE);
throw new BaseException(ErrorCode.FAILED_TO_SEND_GROUP_MESSAGE, e);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.google.auth.oauth2.GoogleCredentials;
import com.google.firebase.FirebaseApp;
import com.google.firebase.FirebaseOptions;
import jakarta.annotation.PostConstruct;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Configuration;
Expand All @@ -18,6 +19,7 @@ public class FirebaseConfig {
@Value("${firebase.admin-sdk}")
private String encodedFirebaseAdminSdk;

@PostConstruct
public FirebaseApp firebaseApp() throws IOException {
byte[] decodedBytes = Base64.getDecoder().decode(encodedFirebaseAdminSdk);
ByteArrayInputStream adminSdk = new ByteArrayInputStream(decodedBytes);
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/com/nexters/goalpanzi/exception/ErrorCode.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ public enum ErrorCode {
FILE_UPLOAD_FAILED("파일 업로드에 실패하였습니다. [%s]"),

// FIREBASE
FAILED_TO_SEND_INDIVIDUAL_MESSAGE("개인 푸시 알림을 보내는 데 실패하였습니다."),
FAILED_TO_SEND_GROUP_MESSAGE("그룹 푸시 알림을 보내는 데 실패하였습니다."),
FAILED_TO_SEND_INDIVIDUAL_MESSAGE("개인 푸시 알림을 보내는 데 실패하였습니다. [%s]"),
FAILED_TO_SEND_GROUP_MESSAGE("그룹 푸시 알림을 보내는 데 실패하였습니다. [%s]"),
FAILED_TO_SUBSCRIBE_TO_TOPIC("토픽을 구독하는 데 실패하였습니다."),
FAILED_TO_UNSUBSCRIBE_FROM_TOPIC("토픽을 구독 취소하는 데 실패하였습니다."),

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
import lombok.RequiredArgsConstructor;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
Expand All @@ -27,7 +27,7 @@ public class FcmTestController {
@GetMapping("individual-message")
ResponseEntity<Void> sendIndividualMessage(
@Schema(description = "deviceToken", requiredMode = Schema.RequiredMode.REQUIRED)
@RequestBody final String deviceToken) {
@RequestParam final String deviceToken) {
pushNotificationSender.sendIndividualMessage("개별 메시지 테스트", deviceToken + "으로 개별 메시지를 전송합니다.", deviceToken);

return ResponseEntity.ok().build();
Expand All @@ -37,7 +37,7 @@ ResponseEntity<Void> sendIndividualMessage(
@GetMapping("group-message")
ResponseEntity<Void> sendGroupMessage(
@Schema(description = "deviceToken", requiredMode = Schema.RequiredMode.REQUIRED)
@RequestBody final String deviceToken
@RequestParam final String deviceToken
) {
String topic = "topic-test";
topicSubscriber.subscribeToTopic(List.of(deviceToken), topic);
Expand Down

0 comments on commit f55db8a

Please sign in to comment.