Skip to content

Commit f2cd906

Browse files
authored
Merge pull request #136 from DogCatSquare/feat/gabi/notification
알림 기능 환경 변수 설정
2 parents fe6b684 + a6d2d51 commit f2cd906

File tree

3 files changed

+13
-9
lines changed

3 files changed

+13
-9
lines changed

src/main/java/DC_square/spring/config/FirebaseInitialization.java

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,23 +6,27 @@
66
import org.springframework.stereotype.Service;
77

88
import javax.annotation.PostConstruct;
9-
import java.io.IOException;
10-
import java.io.InputStream;
9+
import java.io.ByteArrayInputStream;
10+
import java.nio.charset.StandardCharsets;
1111

1212
@Service
1313
public class FirebaseInitialization {
1414

1515
@PostConstruct
1616
public void initialize() {
1717
try {
18-
InputStream serviceAccount = getClass().getClassLoader().getResourceAsStream("firebase-service-account.json");
18+
String firebaseConfig = System.getenv("FIREBASE_CONFIG");
1919

20-
if (serviceAccount == null) {
21-
throw new RuntimeException("firebase-service-account.json 파일을 resources 폴더에서 찾을 수 없습니다.");
20+
if (firebaseConfig == null || firebaseConfig.isEmpty()) {
21+
throw new RuntimeException("환경변수 FIREBASE_CONFIG가 설정되어 있지 않습니다.");
2222
}
2323

24+
GoogleCredentials credentials = GoogleCredentials.fromStream(
25+
new ByteArrayInputStream(firebaseConfig.getBytes(StandardCharsets.UTF_8))
26+
);
27+
2428
FirebaseOptions options = new FirebaseOptions.Builder()
25-
.setCredentials(GoogleCredentials.fromStream(serviceAccount))
29+
.setCredentials(credentials)
2630
.build();
2731

2832
if (FirebaseApp.getApps().isEmpty()) {
@@ -31,7 +35,8 @@ public void initialize() {
3135
} else {
3236
System.out.println("FirebaseApp 이미 초기화되어 있음");
3337
}
34-
} catch (IOException e) {
38+
39+
} catch (Exception e) {
3540
e.printStackTrace();
3641
throw new RuntimeException("Firebase 초기화 중 오류 발생: " + e.getMessage());
3742
}

src/main/java/DC_square/spring/service/dday/DdayService.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ public void sendDdayNotification() {
140140
long daysRemaining = ChronoUnit.DAYS.between(today, dday.getDay());
141141
log.info("D-day: {}, 남은 일수: {}", dday.getTitle(), daysRemaining);
142142

143-
if (daysRemaining >= 0 && daysRemaining <= 365) {
143+
if (daysRemaining >= 0 && daysRemaining <= 7) {
144144
String title = "주기 알림";
145145
String body = daysRemaining == 0
146146
? dday.getTitle() + " 디데이입니다!"

src/main/resources/application.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,4 +87,3 @@ weather:
8787

8888

8989

90-

0 commit comments

Comments
 (0)