-
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.
* chore : Firebase 라이브러리 추가 * feat : Alert 도메인모델, 엔티티 * feat : 알림 전송 로직 구현 * remove : 기존에 있던 파베 설정클래스 제거 * edit : Content 응답 통일 (categpry 관련) * feat : CategoryInfo 생성
- Loading branch information
1 parent
0837e4f
commit 51af067
Showing
10 changed files
with
131 additions
and
29 deletions.
There are no files selected for viewing
1 change: 1 addition & 0 deletions
1
adapters/in-web/src/main/kotlin/com/pokit/content/dto/response/ContentsResponse.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
52 changes: 52 additions & 0 deletions
52
...rs/out-persistence/src/main/kotlin/com/pokit/out/persistence/alert/persist/AlertEntity.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,52 @@ | ||
package com.pokit.out.persistence.alert.persist | ||
|
||
import com.pokit.alert.model.Alert | ||
import com.pokit.content.model.ContentInfo | ||
import com.pokit.out.persistence.BaseEntity | ||
import jakarta.persistence.* | ||
|
||
@Table(name = "ALERT") | ||
@Entity | ||
class AlertEntity( | ||
@Id | ||
@GeneratedValue(strategy = GenerationType.IDENTITY) | ||
@Column(name = "id") | ||
val id: Long = 0L, | ||
|
||
@Column(name = "user_id") | ||
val userId: Long, | ||
|
||
@Column(name = "content_id") | ||
val contentId: Long, | ||
|
||
@Column(name = "content_thumb_nail") | ||
val contentThumbNail: String, | ||
|
||
@Column(name = "title") | ||
val title: String, | ||
|
||
@Column(name = "body") | ||
val body: String, | ||
|
||
@Column(name = "is_deleted") | ||
val deleted: Boolean = false | ||
|
||
) : BaseEntity() { | ||
companion object { | ||
fun of(alert: Alert) = AlertEntity( | ||
userId = alert.userId, | ||
contentId = alert.content.contentId, | ||
contentThumbNail = alert.content.contentThumbNail, | ||
title = alert.title, | ||
body = alert.body, | ||
) | ||
} | ||
} | ||
|
||
fun AlertEntity.toDomain() = Alert( | ||
id = this.id, | ||
userId = this.userId, | ||
content = ContentInfo(this.contentId, this.contentThumbNail), | ||
title = this.title, | ||
body = this.body, | ||
) |
23 changes: 0 additions & 23 deletions
23
...persistence/src/main/kotlin/com/pokit/out/persistence/alert/persist/NotificationEntity.kt
This file was deleted.
Oops, something went wrong.
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
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,42 @@ | ||
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.Alert | ||
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" // 앱 로고 | ||
} | ||
|
||
override fun sendMessage(tokens: List<String>, alert: Alert) { | ||
val notification = Notification.builder() | ||
.setTitle(alert.title) | ||
.setBody(alert.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.Alert | ||
|
||
interface AlertSender { | ||
fun sendMessage(tokens: List<String>, alert: Alert) | ||
} |
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,11 @@ | ||
package com.pokit.alert.model | ||
|
||
import com.pokit.content.model.ContentInfo | ||
|
||
data class Alert( | ||
val id: Long, | ||
val userId: Long, | ||
val content: ContentInfo, | ||
val title: String, | ||
val body: 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