-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat : 알림 전송 기능 * fix : 테스트 버그 수정 * edit : 알림 전송 함수 파라미터 수정
- Loading branch information
1 parent
8dd9888
commit 7fbda94
Showing
7 changed files
with
92 additions
and
6 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
23 changes: 23 additions & 0 deletions
23
adapters/out-web/src/main/kotlin/com/pokit/alert/config/FirebaseConfig.kt
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,23 @@ | ||
package com.pokit.alert.config | ||
|
||
import com.google.auth.oauth2.GoogleCredentials | ||
import com.google.firebase.FirebaseApp | ||
import com.google.firebase.FirebaseOptions | ||
import org.springframework.context.annotation.Bean | ||
import org.springframework.context.annotation.Configuration | ||
import org.springframework.core.io.ClassPathResource | ||
|
||
@Configuration | ||
class FirebaseConfig { | ||
@Bean | ||
fun firebaseApp(): FirebaseApp { | ||
val resource = ClassPathResource("google-services.json") | ||
val serviceAccount = resource.inputStream | ||
|
||
val options = FirebaseOptions.builder() | ||
.setCredentials(GoogleCredentials.fromStream(serviceAccount)) | ||
.build() | ||
|
||
return FirebaseApp.initializeApp(options) | ||
} | ||
} |
43 changes: 43 additions & 0 deletions
43
adapters/out-web/src/main/kotlin/com/pokit/alert/impl/FcmSender.kt
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,43 @@ | ||
package com.pokit.alert.impl | ||
|
||
import com.google.firebase.messaging.FirebaseMessaging | ||
import com.google.firebase.messaging.FirebaseMessagingException | ||
import com.google.firebase.messaging.Message | ||
import com.google.firebase.messaging.Notification | ||
import com.pokit.alert.model.AlertBatch | ||
import com.pokit.alert.port.out.AlertSender | ||
import io.github.oshai.kotlinlogging.KotlinLogging | ||
import org.springframework.stereotype.Component | ||
|
||
@Component | ||
class FcmSender : AlertSender { | ||
private val logger = KotlinLogging.logger { } | ||
|
||
companion object { | ||
const val IMAGE_PATH = "https://pokit-storage.s3.ap-northeast-2.amazonaws.com/logo/pokit.png" // 앱 로고 | ||
const val title = "잊지 말고 링크를 확인하세요!" | ||
const val body = "저장하신 링크가 기다리고 있어요.\n잊지 말고 링크를 확인하세요!" | ||
} | ||
|
||
override fun send(tokens: List<String>) { | ||
val notification = Notification.builder() | ||
.setTitle(title) | ||
.setBody(body) | ||
.setImage(IMAGE_PATH) | ||
.build() | ||
val messages = tokens.map { | ||
Message.builder() | ||
.setNotification(notification) | ||
.setToken(it) | ||
.build() | ||
} | ||
|
||
try { | ||
messages.forEach { | ||
FirebaseMessaging.getInstance().sendAsync(it) | ||
} | ||
} catch (e: FirebaseMessagingException) { | ||
logger.warn { "Failed To Send Message : ${e.message}" } | ||
} | ||
} | ||
} |
7 changes: 7 additions & 0 deletions
7
application/src/main/kotlin/com/pokit/alert/port/out/AlertSender.kt
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,7 @@ | ||
package com.pokit.alert.port.out | ||
|
||
import com.pokit.alert.model.AlertBatch | ||
|
||
interface AlertSender { | ||
fun send(tokens: List<String>) | ||
} |
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