Skip to content

Commit

Permalink
Merge pull request #63 from TelePigeon/fix/62
Browse files Browse the repository at this point in the history
[fix] firebaseconfig 수정
  • Loading branch information
minwoo0419 authored Jun 5, 2024
2 parents ee6cc22 + 42d9dc6 commit 25d0ef2
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 14 deletions.
24 changes: 12 additions & 12 deletions src/main/java/com/telepigeon/server/config/FirebaseConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,35 +3,35 @@
import com.google.auth.oauth2.GoogleCredentials;
import com.google.firebase.FirebaseApp;
import com.google.firebase.FirebaseOptions;
import com.google.firebase.messaging.FirebaseMessaging;
import com.telepigeon.server.exception.NotFoundException;
import com.telepigeon.server.exception.code.NotFoundErrorCode;
import org.springframework.context.annotation.Bean;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Configuration;

import javax.annotation.PostConstruct;
import java.io.FileInputStream;
import java.io.IOException;

@Slf4j
@Configuration
public class FirebaseConfig {
@Bean
public FirebaseApp firebaseApp() {
if (!FirebaseApp.getApps().isEmpty())
return FirebaseApp.getInstance();
@PostConstruct
public void init() {
if (!FirebaseApp.getApps().isEmpty()) {
log.info("FirebaseApp already initialized");
return;
}
try {
FileInputStream aboutFirebaseFile = new FileInputStream("src/main/resources/firebase.json");
FirebaseOptions options = FirebaseOptions
.builder()
.setCredentials(GoogleCredentials.fromStream(aboutFirebaseFile))
.build();
return FirebaseApp.initializeApp(options);
log.info("FirebaseApp initialize");
FirebaseApp.initializeApp(options);
} catch (IOException e) {
log.error("FirebaseApp initialize failed : {}", e.getMessage());
throw new NotFoundException(NotFoundErrorCode.FIREBASE_JSON_NOT_FOUND);
}
}

@Bean
public FirebaseMessaging firebaseMessaging(FirebaseApp firebaseApp) {
return FirebaseMessaging.getInstance(firebaseApp);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,14 @@
@Component
@RequiredArgsConstructor
public class FcmService {
private final FirebaseMessaging firebaseMessaging;

public void send(
final String fcmToken,
final FcmMessageDto fcmMessageDto
){
Message message = createMessage(fcmToken, fcmMessageDto);
try{
firebaseMessaging.send(message);
FirebaseMessaging.getInstance().send(message);
} catch (FirebaseMessagingException e){
throw new BusinessException(BusinessErrorCode.FCM_SERVER_ERROR);
}
Expand Down

0 comments on commit 25d0ef2

Please sign in to comment.