-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: FCM Config 추가 * feat: FCM Info 추가 및 토큰 갱신, 알림 허용 여부 API 추가 * fix: spotlessApply * fix: PostConstruct javax -> jakarta * feat: Notification gitkeep 추가 * fix: 메서드 명 변경 * fix: @kdomo 리뷰 반영 * fix: description 수정 * fix: appAlarm default 값 true로 변경 * fix: return 형 void로 수정 * fix: spotlessApply * fix: throw 에러 출력 변경 * fix: 필요없는 코드 삭제 * fix: slf4j info -> error
- Loading branch information
Showing
14 changed files
with
173 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
src/main/java/com/depromeet/domain/member/domain/FcmInfo.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package com.depromeet.domain.member.domain; | ||
|
||
import jakarta.persistence.Embeddable; | ||
import lombok.AccessLevel; | ||
import lombok.Builder; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
|
||
@Embeddable | ||
@Getter | ||
@NoArgsConstructor(access = AccessLevel.PROTECTED) | ||
public class FcmInfo { | ||
|
||
private String fcmToken; | ||
private Boolean appAlarm; | ||
|
||
@Builder(access = AccessLevel.PRIVATE) | ||
private FcmInfo(String fcmToken, Boolean appAlarm) { | ||
this.fcmToken = fcmToken; | ||
this.appAlarm = appAlarm; | ||
} | ||
|
||
public static FcmInfo createFcmInfo() { | ||
return FcmInfo.builder().fcmToken("").appAlarm(true).build(); | ||
} | ||
|
||
public static FcmInfo toggleAlarm(FcmInfo fcmState) { | ||
return new FcmInfo(fcmState.getFcmToken(), !fcmState.getAppAlarm()); | ||
} | ||
|
||
public static FcmInfo disableAlarm(FcmInfo fcmInfo) { | ||
return new FcmInfo(fcmInfo.getFcmToken(), false); | ||
} | ||
|
||
public static FcmInfo deleteToken(FcmInfo fcmInfo) { | ||
return new FcmInfo("", fcmInfo.getAppAlarm()); | ||
} | ||
|
||
public static FcmInfo updateToken(FcmInfo fcmState, String fcmToken) { | ||
return new FcmInfo(fcmToken, fcmState.getAppAlarm()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 6 additions & 0 deletions
6
src/main/java/com/depromeet/domain/member/dto/request/UpdateFcmTokenRequest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package com.depromeet.domain.member.dto.request; | ||
|
||
import io.swagger.v3.oas.annotations.media.Schema; | ||
|
||
public record UpdateFcmTokenRequest( | ||
@Schema(description = "FCM 토큰", defaultValue = "fcm-token-value") String fcmToken) {} |
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
38 changes: 38 additions & 0 deletions
38
src/main/java/com/depromeet/global/config/fcm/FcmConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package com.depromeet.global.config.fcm; | ||
|
||
import com.google.auth.oauth2.GoogleCredentials; | ||
import com.google.firebase.FirebaseApp; | ||
import com.google.firebase.FirebaseOptions; | ||
import jakarta.annotation.PostConstruct; | ||
import java.io.ByteArrayInputStream; | ||
import java.nio.charset.StandardCharsets; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.beans.factory.annotation.Value; | ||
import org.springframework.context.annotation.Configuration; | ||
|
||
@Configuration | ||
@Slf4j | ||
public class FcmConfig { | ||
|
||
@Value("${fcm.certification}") | ||
private String fcmCertification; | ||
|
||
@PostConstruct | ||
public void init() { | ||
try { | ||
if (FirebaseApp.getApps().isEmpty()) { | ||
FirebaseOptions options = | ||
new FirebaseOptions.Builder() | ||
.setCredentials( | ||
GoogleCredentials.fromStream( | ||
new ByteArrayInputStream( | ||
fcmCertification.getBytes( | ||
StandardCharsets.UTF_8)))) | ||
.build(); | ||
FirebaseApp.initializeApp(options); | ||
} | ||
} catch (Exception e) { | ||
log.error("FCM initializing Exception: {}", e.getStackTrace()[0]); | ||
} | ||
} | ||
} |
40 changes: 40 additions & 0 deletions
40
src/main/java/com/depromeet/global/config/fcm/FcmService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package com.depromeet.global.config.fcm; | ||
|
||
import com.google.api.core.ApiFuture; | ||
import com.google.firebase.messaging.*; | ||
import java.util.List; | ||
import org.springframework.stereotype.Service; | ||
|
||
@Service | ||
public class FcmService { | ||
|
||
/** | ||
* 참고: https://firebase.google.com/support/release-notes/admin/java 위 레퍼런스에 의거하여 | ||
* sendMulticastAsync 는 Deprecated 되어 sendEachForMulticastAsync | ||
* | ||
* @param tokenList: 푸시 토큰 리스트 | ||
* @param title: 알림 제목 | ||
* @param content: 알림 내용 | ||
* @return ApiFuture<BatchResponse> | ||
*/ | ||
public ApiFuture<BatchResponse> sendGroupMessageAsync( | ||
List<String> tokenList, String title, String content) { | ||
MulticastMessage multicast = | ||
MulticastMessage.builder() | ||
.addAllTokens(tokenList) | ||
.setNotification( | ||
Notification.builder().setTitle(title).setBody(content).build()) | ||
.build(); | ||
return FirebaseMessaging.getInstance().sendEachForMulticastAsync(multicast); | ||
} | ||
|
||
public ApiFuture<String> sendMessageSync(String token, String title, String content) { | ||
Message message = | ||
Message.builder() | ||
.setToken(token) | ||
.setNotification( | ||
Notification.builder().setTitle(title).setBody(content).build()) | ||
.build(); | ||
return FirebaseMessaging.getInstance().sendAsync(message); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -30,3 +30,6 @@ springdoc: | |
logging: | ||
level: | ||
com.depromeet.domain.*.api.*: debug | ||
|
||
fcm: | ||
certification: ${FCM_CERTIFICATION:} |