Skip to content

Commit

Permalink
Merge pull request #240 from TeamDon-tBe/fix/#239
Browse files Browse the repository at this point in the history
[FIX]FCM관련 테스트용 코드들 삭제
  • Loading branch information
Hong0329 authored May 27, 2024
2 parents 322fc0d + a44125c commit 4fcc170
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 49 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -113,29 +113,29 @@ public void likeContent(Long memberId, Long contentId, ContentLikedRequestDto co
.notificationText("")
.build();
Notification savedNotification = notificationRepository.save(notification);
}

if (Boolean.TRUE.equals(targetMember.getIsPushAlarmAllowed())) {
String FcmMessageTitle = triggerMember.getNickname() + "님이 " + targetMember.getNickname() + "님의 글을 좋아합니다.";

FcmMessageDto contentLikeFcmMessage = FcmMessageDto.builder()
.validateOnly(false)
.message(FcmMessageDto.Message.builder()
.notificationDetails(FcmMessageDto.NotificationDetails.builder()
.title(FcmMessageTitle)
.body("")
.build())
.token(targetMember.getFcmToken())
.data(FcmMessageDto.Data.builder()
.name("contentLike")
.description("게시글 좋아요 푸시 알림")
.relateContentId(String.valueOf(contentId))
.build())
.build())
.build();

fcmService.sendMessage(contentLikeFcmMessage);

if (Boolean.TRUE.equals(targetMember.getIsPushAlarmAllowed())) {
String FcmMessageTitle = triggerMember.getNickname() + "님이 " + targetMember.getNickname() + "님의 글을 좋아합니다.";

FcmMessageDto contentLikeFcmMessage = FcmMessageDto.builder()
.validateOnly(false)
.message(FcmMessageDto.Message.builder()
.notificationDetails(FcmMessageDto.NotificationDetails.builder()
.title(FcmMessageTitle)
.body("")
.build())
.token(targetMember.getFcmToken())
.data(FcmMessageDto.Data.builder()
.name("contentLike")
.description("게시글 좋아요 푸시 알림")
.relateContentId(String.valueOf(contentId))
.build())
.build())
.build();

fcmService.sendMessage(contentLikeFcmMessage);
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,7 @@
import org.springframework.stereotype.Service;

import javax.annotation.PostConstruct;
import java.io.ByteArrayInputStream;
import java.io.FileInputStream;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.util.Map;

@Service
Expand All @@ -27,34 +24,10 @@ public class FcmService {
private final ObjectMapper objectMapper;

@PostConstruct
// public void initialize() throws IOException {
// try {
// ClassPathResource resource = new ClassPathResource("fire-base.json");
//
// String jsonString = new String(resource.getInputStream().readAllBytes(), StandardCharsets.UTF_8);
// System.out.println("Firebase JSON content: " + jsonString);
//
// GoogleCredentials credentials = GoogleCredentials.fromStream(resource.getInputStream());
// FirebaseOptions options = FirebaseOptions.builder()
// .setCredentials(credentials)
// .build();
// if (FirebaseApp.getApps().isEmpty()) {
// FirebaseApp.initializeApp(options);
// }
// } catch (IOException e) {
// System.out.println(e.getMessage());
// }
// }
public void initialize() throws IOException {
try {
ClassPathResource resource = new ClassPathResource("fire-base.json");

String jsonString = new String(resource.getInputStream().readAllBytes(), StandardCharsets.UTF_8);
System.out.println("Firebase JSON content: " + jsonString);

ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(jsonString.getBytes(StandardCharsets.UTF_8));

GoogleCredentials credentials = GoogleCredentials.fromStream(byteArrayInputStream);
GoogleCredentials credentials = GoogleCredentials.fromStream(resource.getInputStream());
FirebaseOptions options = FirebaseOptions.builder()
.setCredentials(credentials)
.build();
Expand All @@ -66,6 +39,7 @@ public void initialize() throws IOException {
}
}


public void sendMessage(FcmMessageDto fcmMessageDto) {
Message message = Message.builder()
.setToken(fcmMessageDto.getMessage().getToken())
Expand Down

0 comments on commit 4fcc170

Please sign in to comment.