generated from GSM-MSG/MSG-Repository-Generator
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #350 from GSM-MSG/349-refactor/message-util-with-s…
…pring-event 🔀 :: 349 refactor/message util with spring event
- Loading branch information
Showing
20 changed files
with
266 additions
and
135 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
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
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
11 changes: 11 additions & 0 deletions
11
src/main/kotlin/com/msg/gcms/global/event/SendMessageEvent.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,11 @@ | ||
package com.msg.gcms.global.event | ||
|
||
import com.msg.gcms.domain.user.domain.entity.User | ||
import com.msg.gcms.global.fcm.enums.SendType | ||
|
||
data class SendMessageEvent( | ||
val user: User, | ||
val title: String, | ||
val content: String, | ||
val type: SendType | ||
) |
40 changes: 40 additions & 0 deletions
40
src/main/kotlin/com/msg/gcms/global/handler/MessageEventHandler.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,40 @@ | ||
package com.msg.gcms.global.handler | ||
|
||
import com.google.firebase.messaging.* | ||
import com.msg.gcms.domain.user.domain.repository.DeviceTokenRepository | ||
import com.msg.gcms.global.event.SendMessageEvent | ||
import org.springframework.data.repository.findByIdOrNull | ||
import org.springframework.stereotype.Component | ||
import org.springframework.transaction.event.TransactionPhase | ||
import org.springframework.transaction.event.TransactionalEventListener | ||
|
||
@Component | ||
class MessageEventHandler( | ||
private val deviceTokenRepository: DeviceTokenRepository | ||
) { | ||
@TransactionalEventListener(phase = TransactionPhase.AFTER_COMMIT) | ||
fun send(sendMessageEvent: SendMessageEvent) { | ||
val deviceToken = deviceTokenRepository.findByIdOrNull(sendMessageEvent.user.id) | ||
?: return | ||
|
||
if(!deviceToken.token.isNullOrBlank()) { | ||
val message = Message.builder() | ||
.setToken(deviceToken.token) | ||
.putData("type", sendMessageEvent.type.name) | ||
.setNotification( | ||
Notification.builder() | ||
.setTitle(sendMessageEvent.title) | ||
.setBody(sendMessageEvent.content) | ||
.build() | ||
) | ||
.setApnsConfig( | ||
ApnsConfig.builder() | ||
.setAps(Aps.builder().setSound("default").build()) | ||
.build() | ||
) | ||
.build() | ||
|
||
FirebaseMessaging.getInstance().sendAsync(message) | ||
} | ||
} | ||
} |
10 changes: 0 additions & 10 deletions
10
src/main/kotlin/com/msg/gcms/global/util/MessageSendUtil.kt
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.