-
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.
- Loading branch information
1 parent
20802e6
commit f0ec85a
Showing
14 changed files
with
155 additions
and
27 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
5 changes: 3 additions & 2 deletions
5
src/main/kotlin/com/hero/alignlab/client/discord/client/DiscordWebhookClient.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 |
---|---|---|
@@ -1,10 +1,11 @@ | ||
package com.hero.alignlab.client.discord.client | ||
|
||
import com.hero.alignlab.client.discord.config.DiscordWebhookClientConfig | ||
import com.hero.alignlab.client.discord.model.request.SendMessageRequest | ||
import com.hero.alignlab.client.discord.model.response.GetWebhookWithTokenResponse | ||
|
||
interface DiscordWebhookClient { | ||
suspend fun getWebhookWithToken(): GetWebhookWithTokenResponse | ||
suspend fun getWebhookWithToken(channel: DiscordWebhookClientConfig.Config.Channel): GetWebhookWithTokenResponse | ||
|
||
suspend fun sendMessage(request: SendMessageRequest) | ||
suspend fun sendMessage(channel: DiscordWebhookClientConfig.Config.Channel, request: SendMessageRequest) | ||
} |
15 changes: 13 additions & 2 deletions
15
src/main/kotlin/com/hero/alignlab/client/discord/client/SuspendableDiscordWebhookClient.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 |
---|---|---|
@@ -1,23 +1,34 @@ | ||
package com.hero.alignlab.client.discord.client | ||
|
||
import com.hero.alignlab.client.discord.config.DiscordWebhookClientConfig.Config.Channel | ||
import com.hero.alignlab.client.discord.config.DiscordWebhookClientConfig.Config.Token | ||
import com.hero.alignlab.client.discord.model.request.SendMessageRequest | ||
import com.hero.alignlab.client.discord.model.response.GetWebhookWithTokenResponse | ||
import com.hero.alignlab.client.kakao.SuspendableClient | ||
import com.hero.alignlab.exception.ErrorCode | ||
import com.hero.alignlab.exception.NotFoundException | ||
import org.springframework.web.reactive.function.client.WebClient | ||
|
||
class SuspendableDiscordWebhookClient( | ||
client: WebClient, | ||
private val targets: Map<Channel, Token>, | ||
) : DiscordWebhookClient, SuspendableClient(client) { | ||
override suspend fun getWebhookWithToken(): GetWebhookWithTokenResponse { | ||
override suspend fun getWebhookWithToken(channel: Channel): GetWebhookWithTokenResponse { | ||
return client | ||
.get() | ||
.uri(resolveTargetToken(channel)) | ||
.request() | ||
} | ||
|
||
override suspend fun sendMessage(request: SendMessageRequest) { | ||
override suspend fun sendMessage(channel: Channel, request: SendMessageRequest) { | ||
return client | ||
.post() | ||
.uri(resolveTargetToken(channel)) | ||
.bodyValue(request) | ||
.request() | ||
} | ||
|
||
private fun resolveTargetToken(channel: Channel): String { | ||
return targets[channel]?.token ?: throw NotFoundException(ErrorCode.NOT_FOUND_TARGET_TOKEN) | ||
} | ||
} |
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
45 changes: 45 additions & 0 deletions
45
src/main/kotlin/com/hero/alignlab/event/listener/DiscussionEventListener.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,45 @@ | ||
package com.hero.alignlab.event.listener | ||
|
||
import com.hero.alignlab.client.discord.client.DiscordWebhookClient | ||
import com.hero.alignlab.client.discord.config.DiscordWebhookClientConfig | ||
import com.hero.alignlab.client.discord.model.request.SendMessageRequest | ||
import com.hero.alignlab.domain.user.application.UserInfoService | ||
import com.hero.alignlab.event.model.DiscussionEvent | ||
import kotlinx.coroutines.CoroutineScope | ||
import kotlinx.coroutines.Dispatchers | ||
import kotlinx.coroutines.Job | ||
import kotlinx.coroutines.launch | ||
import org.springframework.stereotype.Component | ||
import org.springframework.transaction.event.TransactionalEventListener | ||
import java.time.LocalDateTime | ||
import java.time.format.DateTimeFormatter | ||
|
||
@Component | ||
class DiscussionEventListener( | ||
private val discordWebhookClient: DiscordWebhookClient, | ||
private val userInfoService: UserInfoService, | ||
) { | ||
@TransactionalEventListener | ||
fun handle(event: DiscussionEvent) { | ||
CoroutineScope(Dispatchers.IO + Job()).launch { | ||
val formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss") | ||
|
||
val userInfo = userInfoService.getUserInfo(event.discussion.uid) | ||
|
||
val message = """ | ||
**문의하기 [${LocalDateTime.now().format(formatter)}]** | ||
- 유저명 : ${userInfo.nickname} | ||
- 이메일 : ${event.discussion.email ?: "없음"} | ||
- type : ${event.discussion.type} | ||
- title : ${event.discussion.title} | ||
- content : ${event.discussion.content} | ||
""".trimIndent() | ||
|
||
discordWebhookClient.sendMessage( | ||
channel = DiscordWebhookClientConfig.Config.Channel.DISCUSSION, | ||
request = SendMessageRequest(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
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