From d09de65dfdd50e026421d5b13830fcc8f70ba330 Mon Sep 17 00:00:00 2001 From: wonjunYou Date: Wed, 30 Oct 2024 15:09:21 +0900 Subject: [PATCH 1/8] =?UTF-8?q?[IDLE-476]=20=EC=9B=B9=EC=86=8C=EC=BC=93=20?= =?UTF-8?q?dependency=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- gradle/libs.versions.toml | 1 + idle-presentation/build.gradle.kts | 1 + 2 files changed, 2 insertions(+) diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 80750d30..5aec7b4b 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -75,6 +75,7 @@ kotest-assertions-core = { group = "io.kotest", name = "kotest-assertions-core", kotest-extensions-spring = { group = "io.kotest.extensions", name = "kotest-extensions-spring", version.ref = "kotest-extensions-spring" } spring-boot-starter-actuator = { group = "org.springframework.boot", name = "spring-boot-starter-actuator", version.ref = "spring-boot" } spring-boot-starter-test = { group = "org.springframework.boot", name = "spring-boot-starter-test", version.ref = "spring-boot" } +spring-boot-starter-websocket = { group = "org.springframework.boot", name = "spring-boot-starter-websocket", version.ref = "spring-boot" } kotest-extensions-testcontainers = { group = "io.kotest.extensions", name = "kotest-extensions-testcontainers", version.ref = "kotest-extensions-testcontainers" } testcontainers-junit-jupiter = { group = "org.testcontainers", name = "junit-jupiter", version.ref = "testcontainers" } diff --git a/idle-presentation/build.gradle.kts b/idle-presentation/build.gradle.kts index 24e97e3a..db5712ab 100644 --- a/idle-presentation/build.gradle.kts +++ b/idle-presentation/build.gradle.kts @@ -13,6 +13,7 @@ dependencies { implementation(project(":idle-infrastructure:monitoring")) implementation(libs.spring.boot.starter.web) + implementation(libs.spring.boot.starter.websocket) implementation(libs.spring.boot.starter.data.jpa) implementation(libs.springdoc.openapi.starter.webmvc.ui) From 0b223524ce5b7aae567d81e70098e9c8e5ba05dd Mon Sep 17 00:00:00 2001 From: wonjunYou Date: Wed, 30 Oct 2024 22:23:18 +0900 Subject: [PATCH 2/8] =?UTF-8?q?[IDLE-476]=20=EC=9B=B9=EC=86=8C=EC=BC=93,?= =?UTF-8?q?=20Redis=20pub/sub=EC=9D=84=20=EC=9D=B4=EC=9A=A9=ED=95=9C=20?= =?UTF-8?q?=EC=B1=84=ED=8C=85=20=EC=A0=84=EC=86=A1=20=EA=B8=B0=EB=8A=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../chat/domain/ChatMessageService.kt | 24 +++++++++++ .../chat/event/ChatMessagePublisher.kt | 16 ++++++++ .../chat/facade/ChatMessageFacadeService.kt | 35 ++++++++++++++++ .../chat/facade/ChatRoomFacadeService.kt | 7 ++++ .../chat/config/ChatMessageRedisConfig.kt | 41 +++++++++++++++++++ .../chat/event/ChatMessageRedisConsumer.kt | 30 ++++++++++++++ .../chat/event/ChatMessageRedisPublisher.kt | 22 ++++++++++ .../idle/domain/common/config/RedisConfig.kt | 22 ++++++++-- .../chat/config/WebSocketConfig.kt | 29 +++++++++++++ .../chat/controller/ChatMessageHandler.kt | 30 ++++++++++++++ .../controller/ChatWebSocketController.kt | 30 ++++++++++++++ .../transfer/chat/SendChatMessageRequest.kt | 7 ++++ 12 files changed, 289 insertions(+), 4 deletions(-) create mode 100644 idle-application/src/main/kotlin/com/swm/idle/application/chat/domain/ChatMessageService.kt create mode 100644 idle-application/src/main/kotlin/com/swm/idle/application/chat/event/ChatMessagePublisher.kt create mode 100644 idle-application/src/main/kotlin/com/swm/idle/application/chat/facade/ChatMessageFacadeService.kt create mode 100644 idle-application/src/main/kotlin/com/swm/idle/application/chat/facade/ChatRoomFacadeService.kt create mode 100644 idle-domain/src/main/kotlin/com/swm/idle/domain/chat/config/ChatMessageRedisConfig.kt create mode 100644 idle-domain/src/main/kotlin/com/swm/idle/domain/chat/event/ChatMessageRedisConsumer.kt create mode 100644 idle-domain/src/main/kotlin/com/swm/idle/domain/chat/event/ChatMessageRedisPublisher.kt create mode 100644 idle-presentation/src/main/kotlin/com/swm/idle/presentation/chat/config/WebSocketConfig.kt create mode 100644 idle-presentation/src/main/kotlin/com/swm/idle/presentation/chat/controller/ChatMessageHandler.kt create mode 100644 idle-presentation/src/main/kotlin/com/swm/idle/presentation/chat/controller/ChatWebSocketController.kt create mode 100644 idle-support/transfer/src/main/kotlin/com/swm/idle/support/transfer/chat/SendChatMessageRequest.kt diff --git a/idle-application/src/main/kotlin/com/swm/idle/application/chat/domain/ChatMessageService.kt b/idle-application/src/main/kotlin/com/swm/idle/application/chat/domain/ChatMessageService.kt new file mode 100644 index 00000000..431e2846 --- /dev/null +++ b/idle-application/src/main/kotlin/com/swm/idle/application/chat/domain/ChatMessageService.kt @@ -0,0 +1,24 @@ +package com.swm.idle.application.chat.domain + +import com.swm.idle.domain.chat.entity.jpa.ChatMessage +import com.swm.idle.domain.chat.enums.SenderType +import org.springframework.stereotype.Service +import java.util.* + +@Service +class ChatMessageService { + + fun createByUser(roomId: UUID, userId: UUID, contents: List): ChatMessage { + return ChatMessage( + roomId = roomId, + senderId = userId, + senderType = SenderType.USER, + contents = contents + ) + } + + fun publish(it: ChatMessage) { + + } + +} diff --git a/idle-application/src/main/kotlin/com/swm/idle/application/chat/event/ChatMessagePublisher.kt b/idle-application/src/main/kotlin/com/swm/idle/application/chat/event/ChatMessagePublisher.kt new file mode 100644 index 00000000..26a50f39 --- /dev/null +++ b/idle-application/src/main/kotlin/com/swm/idle/application/chat/event/ChatMessagePublisher.kt @@ -0,0 +1,16 @@ +package com.swm.idle.application.chat.event + +import com.swm.idle.domain.chat.entity.jpa.ChatMessage +import org.springframework.context.ApplicationEventPublisher +import org.springframework.stereotype.Component + +@Component +class ChatMessagePublisher( + private val eventPublisher: ApplicationEventPublisher, +) { + + fun publish(chatMessage: ChatMessage) { + eventPublisher.publishEvent(chatMessage) + } + +} diff --git a/idle-application/src/main/kotlin/com/swm/idle/application/chat/facade/ChatMessageFacadeService.kt b/idle-application/src/main/kotlin/com/swm/idle/application/chat/facade/ChatMessageFacadeService.kt new file mode 100644 index 00000000..0a9737d0 --- /dev/null +++ b/idle-application/src/main/kotlin/com/swm/idle/application/chat/facade/ChatMessageFacadeService.kt @@ -0,0 +1,35 @@ +package com.swm.idle.application.chat.facade + +import com.swm.idle.application.chat.domain.ChatMessageService +import com.swm.idle.domain.chat.entity.jpa.ChatMessage +import com.swm.idle.domain.chat.enums.SenderType +import com.swm.idle.domain.chat.event.ChatMessageRedisPublisher +import org.springframework.stereotype.Service +import java.util.* + +@Service +class ChatMessageFacadeService( + private val chatMessageRedisPublisher: ChatMessageRedisPublisher, + private val chatMessageService: ChatMessageService, +) { + + fun sendTextMessage( + roomId: UUID, + senderId: UUID, + contents: List, + ) { + ChatMessage( + roomId = roomId, + senderId = senderId, + senderType = SenderType.USER, + contents = contents + ).also { + chatMessageRedisPublisher.publish(it) + } + } + + fun saveMessage(chatMessage: ChatMessage) { + // TODO : 메세지 저장 로직 구현 + } + +} diff --git a/idle-application/src/main/kotlin/com/swm/idle/application/chat/facade/ChatRoomFacadeService.kt b/idle-application/src/main/kotlin/com/swm/idle/application/chat/facade/ChatRoomFacadeService.kt new file mode 100644 index 00000000..29c73dbe --- /dev/null +++ b/idle-application/src/main/kotlin/com/swm/idle/application/chat/facade/ChatRoomFacadeService.kt @@ -0,0 +1,7 @@ +package com.swm.idle.application.chat.facade + +import org.springframework.stereotype.Service + +@Service +class ChatRoomFacadeService { +} diff --git a/idle-domain/src/main/kotlin/com/swm/idle/domain/chat/config/ChatMessageRedisConfig.kt b/idle-domain/src/main/kotlin/com/swm/idle/domain/chat/config/ChatMessageRedisConfig.kt new file mode 100644 index 00000000..b77637f4 --- /dev/null +++ b/idle-domain/src/main/kotlin/com/swm/idle/domain/chat/config/ChatMessageRedisConfig.kt @@ -0,0 +1,41 @@ +package com.swm.idle.domain.chat.config + +import com.swm.idle.domain.chat.event.ChatMessageRedisConsumer +import org.springframework.context.annotation.Bean +import org.springframework.context.annotation.Configuration +import org.springframework.data.redis.connection.RedisConnectionFactory +import org.springframework.data.redis.listener.ChannelTopic +import org.springframework.data.redis.listener.RedisMessageListenerContainer +import org.springframework.data.redis.listener.adapter.MessageListenerAdapter + +@Configuration +class ChatMessageRedisConfig { + + @Bean + fun redisListenerContainer( + connectionFactory: RedisConnectionFactory, + messageListenerAdapter: MessageListenerAdapter, + ): RedisMessageListenerContainer { + val container = RedisMessageListenerContainer() + container.setConnectionFactory(connectionFactory) + container.addMessageListener(messageListenerAdapter, chatChannelTopic()) + return container + } + + @Bean + fun messageListenerAdapter(chatMessageRedisConsumer: ChatMessageRedisConsumer): MessageListenerAdapter { + return MessageListenerAdapter(chatMessageRedisConsumer) + } + + @Bean + fun chatChannelTopic(): ChannelTopic { + return ChannelTopic(CHAT_MESSAGE) + } + + companion object { + + const val CHAT_MESSAGE = "chat_message" + + } + +} diff --git a/idle-domain/src/main/kotlin/com/swm/idle/domain/chat/event/ChatMessageRedisConsumer.kt b/idle-domain/src/main/kotlin/com/swm/idle/domain/chat/event/ChatMessageRedisConsumer.kt new file mode 100644 index 00000000..9c765bb9 --- /dev/null +++ b/idle-domain/src/main/kotlin/com/swm/idle/domain/chat/event/ChatMessageRedisConsumer.kt @@ -0,0 +1,30 @@ +package com.swm.idle.domain.chat.event + +import com.fasterxml.jackson.databind.ObjectMapper +import com.fasterxml.jackson.module.kotlin.readValue +import com.swm.idle.domain.chat.entity.jpa.ChatMessage +import io.github.oshai.kotlinlogging.KotlinLogging +import org.springframework.context.ApplicationEventPublisher +import org.springframework.data.redis.connection.Message +import org.springframework.data.redis.connection.MessageListener +import org.springframework.stereotype.Component + +@Component +class ChatMessageRedisConsumer( + private val applicationEventPublisher: ApplicationEventPublisher, + private val objectMapper: ObjectMapper, +) : MessageListener { + + val logger = KotlinLogging.logger {} + + override fun onMessage( + message: Message, + pattern: ByteArray?, + ) { + logger.debug { "Received message: $message" } + + objectMapper.readValue(message.body) + .also { applicationEventPublisher.publishEvent(it) } + } + +} diff --git a/idle-domain/src/main/kotlin/com/swm/idle/domain/chat/event/ChatMessageRedisPublisher.kt b/idle-domain/src/main/kotlin/com/swm/idle/domain/chat/event/ChatMessageRedisPublisher.kt new file mode 100644 index 00000000..b8a6616f --- /dev/null +++ b/idle-domain/src/main/kotlin/com/swm/idle/domain/chat/event/ChatMessageRedisPublisher.kt @@ -0,0 +1,22 @@ +package com.swm.idle.domain.chat.event + +import com.swm.idle.domain.chat.config.ChatMessageRedisConfig +import com.swm.idle.domain.chat.entity.jpa.ChatMessage +import io.github.oshai.kotlinlogging.KotlinLogging +import org.springframework.data.redis.core.RedisTemplate +import org.springframework.stereotype.Component + +@Component +class ChatMessageRedisPublisher( + private val redisTemplate: RedisTemplate, +) { + + private val logger = KotlinLogging.logger {} + + fun publish(chatMessage: ChatMessage) { + logger.info { "RedisPublisher 도달 " } + + redisTemplate.convertAndSend(ChatMessageRedisConfig.CHAT_MESSAGE, chatMessage) + } + +} diff --git a/idle-domain/src/main/kotlin/com/swm/idle/domain/common/config/RedisConfig.kt b/idle-domain/src/main/kotlin/com/swm/idle/domain/common/config/RedisConfig.kt index 25c63038..c913bbe6 100644 --- a/idle-domain/src/main/kotlin/com/swm/idle/domain/common/config/RedisConfig.kt +++ b/idle-domain/src/main/kotlin/com/swm/idle/domain/common/config/RedisConfig.kt @@ -1,5 +1,8 @@ package com.swm.idle.domain.common.config +import com.fasterxml.jackson.databind.ObjectMapper +import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule +import com.fasterxml.jackson.module.kotlin.KotlinModule import com.swm.idle.domain.common.properties.RedisProperties import org.springframework.boot.context.properties.EnableConfigurationProperties import org.springframework.context.annotation.Bean @@ -10,6 +13,8 @@ import org.springframework.data.redis.connection.RedisStandaloneConfiguration import org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory import org.springframework.data.redis.core.RedisTemplate import org.springframework.data.redis.repository.configuration.EnableRedisRepositories +import org.springframework.data.redis.serializer.GenericJackson2JsonRedisSerializer +import org.springframework.data.redis.serializer.StringRedisSerializer @Configuration @EnableConfigurationProperties(RedisProperties::class) @@ -30,10 +35,19 @@ class RedisConfig( } @Bean - fun redisTemplate(redisConnectionFactory: RedisConnectionFactory?): RedisTemplate<*, *> { - val template = RedisTemplate() - template.connectionFactory = redisConnectionFactory - return template + fun redisTemplate(redisConnectionFactory: RedisConnectionFactory?): RedisTemplate { + val serializer = GenericJackson2JsonRedisSerializer(objectMapper) + + return RedisTemplate().apply { + connectionFactory = redisConnectionFactory!! + keySerializer = StringRedisSerializer() + valueSerializer = serializer + } + } + + private val objectMapper = ObjectMapper().apply { + registerModule(KotlinModule.Builder().build()) + registerModule(JavaTimeModule()) } } diff --git a/idle-presentation/src/main/kotlin/com/swm/idle/presentation/chat/config/WebSocketConfig.kt b/idle-presentation/src/main/kotlin/com/swm/idle/presentation/chat/config/WebSocketConfig.kt new file mode 100644 index 00000000..bd60e8a2 --- /dev/null +++ b/idle-presentation/src/main/kotlin/com/swm/idle/presentation/chat/config/WebSocketConfig.kt @@ -0,0 +1,29 @@ +package com.swm.idle.presentation.chat.config + +import org.springframework.context.annotation.Configuration +import org.springframework.messaging.simp.config.MessageBrokerRegistry +import org.springframework.web.socket.config.annotation.EnableWebSocketMessageBroker +import org.springframework.web.socket.config.annotation.StompEndpointRegistry +import org.springframework.web.socket.config.annotation.WebSocketMessageBrokerConfigurer + +@Configuration +@EnableWebSocketMessageBroker +class WebSocketConfig : WebSocketMessageBrokerConfigurer { + + override fun registerStompEndpoints(registry: StompEndpointRegistry) { + registry + .addEndpoint("/websocket") + .setAllowedOriginPatterns("*") + .withSockJS() + + registry + .addEndpoint("/websocket") + .setAllowedOriginPatterns("*") + } + + override fun configureMessageBroker(registry: MessageBrokerRegistry) { + registry.enableSimpleBroker("/topic") + registry.setApplicationDestinationPrefixes("/app") + } + +} diff --git a/idle-presentation/src/main/kotlin/com/swm/idle/presentation/chat/controller/ChatMessageHandler.kt b/idle-presentation/src/main/kotlin/com/swm/idle/presentation/chat/controller/ChatMessageHandler.kt new file mode 100644 index 00000000..9f925a96 --- /dev/null +++ b/idle-presentation/src/main/kotlin/com/swm/idle/presentation/chat/controller/ChatMessageHandler.kt @@ -0,0 +1,30 @@ +package com.swm.idle.presentation.chat.controller + +import com.swm.idle.application.chat.facade.ChatMessageFacadeService +import com.swm.idle.domain.chat.entity.jpa.ChatMessage +import io.github.oshai.kotlinlogging.KotlinLogging +import org.springframework.context.event.EventListener +import org.springframework.messaging.simp.SimpMessageSendingOperations +import org.springframework.stereotype.Controller + +@Controller +class ChatMessageHandler( + private val simpMessageSendingOperations: SimpMessageSendingOperations, + private val chatMessageFacadeService: ChatMessageFacadeService, +) { + + private val logger = KotlinLogging.logger { } + + @EventListener + fun handleChatMessage(chatMessage: ChatMessage) { + logger.info { "Handler까지 도달 " } + + simpMessageSendingOperations.convertAndSend( + "/topic/chat-rooms/${chatMessage.roomId}", + chatMessage + ) + + chatMessageFacadeService.saveMessage(chatMessage) + } + +} diff --git a/idle-presentation/src/main/kotlin/com/swm/idle/presentation/chat/controller/ChatWebSocketController.kt b/idle-presentation/src/main/kotlin/com/swm/idle/presentation/chat/controller/ChatWebSocketController.kt new file mode 100644 index 00000000..14b0bf32 --- /dev/null +++ b/idle-presentation/src/main/kotlin/com/swm/idle/presentation/chat/controller/ChatWebSocketController.kt @@ -0,0 +1,30 @@ +package com.swm.idle.presentation.chat.controller + +import com.swm.idle.application.chat.facade.ChatMessageFacadeService +import com.swm.idle.support.common.uuid.UuidCreator +import com.swm.idle.support.transfer.chat.SendChatMessageRequest +import org.springframework.messaging.handler.annotation.DestinationVariable +import org.springframework.messaging.handler.annotation.MessageMapping +import org.springframework.messaging.handler.annotation.SendTo +import org.springframework.stereotype.Controller +import java.util.* + +@Controller +class ChatWebSocketController( + private val chatMessageService: ChatMessageFacadeService, +) { + + @MessageMapping("/chat-rooms/{roomId}") + @SendTo("/topic/chat-rooms/{roomId}") + fun sendTextMessage( + @DestinationVariable roomId: UUID, + request: SendChatMessageRequest, + ) { + chatMessageService.sendTextMessage( + roomId = roomId, + senderId = UuidCreator.create(), // TODO: 토큰 인증 구현 + contents = request.contents, + ) + } + +} diff --git a/idle-support/transfer/src/main/kotlin/com/swm/idle/support/transfer/chat/SendChatMessageRequest.kt b/idle-support/transfer/src/main/kotlin/com/swm/idle/support/transfer/chat/SendChatMessageRequest.kt new file mode 100644 index 00000000..fabe0408 --- /dev/null +++ b/idle-support/transfer/src/main/kotlin/com/swm/idle/support/transfer/chat/SendChatMessageRequest.kt @@ -0,0 +1,7 @@ +package com.swm.idle.support.transfer.chat + +import com.swm.idle.domain.chat.entity.jpa.ChatMessage + +data class SendChatMessageRequest( + val contents: List, +) From 0d5787df4eff9bed440231be7408bcfce01191a1 Mon Sep 17 00:00:00 2001 From: wonjunYou Date: Wed, 27 Nov 2024 16:38:55 +0900 Subject: [PATCH 3/8] =?UTF-8?q?[IDLE-476]=20=EB=B6=88=ED=95=84=EC=9A=94=20?= =?UTF-8?q?=ED=81=B4=EB=9E=98=EC=8A=A4=20=EC=A0=9C=EA=B1=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../chat/event/ChatMessagePublisher.kt | 16 ---------------- 1 file changed, 16 deletions(-) delete mode 100644 idle-application/src/main/kotlin/com/swm/idle/application/chat/event/ChatMessagePublisher.kt diff --git a/idle-application/src/main/kotlin/com/swm/idle/application/chat/event/ChatMessagePublisher.kt b/idle-application/src/main/kotlin/com/swm/idle/application/chat/event/ChatMessagePublisher.kt deleted file mode 100644 index 26a50f39..00000000 --- a/idle-application/src/main/kotlin/com/swm/idle/application/chat/event/ChatMessagePublisher.kt +++ /dev/null @@ -1,16 +0,0 @@ -package com.swm.idle.application.chat.event - -import com.swm.idle.domain.chat.entity.jpa.ChatMessage -import org.springframework.context.ApplicationEventPublisher -import org.springframework.stereotype.Component - -@Component -class ChatMessagePublisher( - private val eventPublisher: ApplicationEventPublisher, -) { - - fun publish(chatMessage: ChatMessage) { - eventPublisher.publishEvent(chatMessage) - } - -} From 660b2434ace1f10d6ddc82140f70941b3b6925ba Mon Sep 17 00:00:00 2001 From: wonjunYou Date: Wed, 27 Nov 2024 16:39:27 +0900 Subject: [PATCH 4/8] =?UTF-8?q?[IDLE-476]=20=EC=B1=84=ED=8C=85=20=EB=A9=94?= =?UTF-8?q?=EC=84=B8=EC=A7=80=20=EC=83=9D=EC=84=B1=20=EC=B1=85=EC=9E=84?= =?UTF-8?q?=EC=9D=84=20=ED=95=98=EC=9C=84=20=EB=8F=84=EB=A9=94=EC=9D=B8?= =?UTF-8?q?=EC=97=90=EC=84=9C=20=EC=83=9D=EC=84=B1=ED=95=98=EB=8F=84?= =?UTF-8?q?=EB=A1=9D=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../idle/application/chat/domain/ChatMessageService.kt | 4 ---- .../application/chat/facade/ChatMessageFacadeService.kt | 8 +++----- 2 files changed, 3 insertions(+), 9 deletions(-) diff --git a/idle-application/src/main/kotlin/com/swm/idle/application/chat/domain/ChatMessageService.kt b/idle-application/src/main/kotlin/com/swm/idle/application/chat/domain/ChatMessageService.kt index 431e2846..c2f7c921 100644 --- a/idle-application/src/main/kotlin/com/swm/idle/application/chat/domain/ChatMessageService.kt +++ b/idle-application/src/main/kotlin/com/swm/idle/application/chat/domain/ChatMessageService.kt @@ -17,8 +17,4 @@ class ChatMessageService { ) } - fun publish(it: ChatMessage) { - - } - } diff --git a/idle-application/src/main/kotlin/com/swm/idle/application/chat/facade/ChatMessageFacadeService.kt b/idle-application/src/main/kotlin/com/swm/idle/application/chat/facade/ChatMessageFacadeService.kt index 0a9737d0..5d48e641 100644 --- a/idle-application/src/main/kotlin/com/swm/idle/application/chat/facade/ChatMessageFacadeService.kt +++ b/idle-application/src/main/kotlin/com/swm/idle/application/chat/facade/ChatMessageFacadeService.kt @@ -2,7 +2,6 @@ package com.swm.idle.application.chat.facade import com.swm.idle.application.chat.domain.ChatMessageService import com.swm.idle.domain.chat.entity.jpa.ChatMessage -import com.swm.idle.domain.chat.enums.SenderType import com.swm.idle.domain.chat.event.ChatMessageRedisPublisher import org.springframework.stereotype.Service import java.util.* @@ -18,11 +17,10 @@ class ChatMessageFacadeService( senderId: UUID, contents: List, ) { - ChatMessage( + chatMessageService.createByUser( roomId = roomId, - senderId = senderId, - senderType = SenderType.USER, - contents = contents + userId = senderId, + contents = contents, ).also { chatMessageRedisPublisher.publish(it) } From 4da22d9107feb2be0e2a200ce3281bb8cd6c4a1d Mon Sep 17 00:00:00 2001 From: wonjunYou Date: Wed, 27 Nov 2024 16:39:54 +0900 Subject: [PATCH 5/8] =?UTF-8?q?[IDLE-476]=20hash=20=EC=97=AD=EC=A7=81?= =?UTF-8?q?=EB=A0=AC=ED=99=94=20=EC=8B=9C=20=ED=95=84=EC=9A=94=ED=95=9C=20?= =?UTF-8?q?=EC=B2=98=EB=A6=AC=EB=A5=BC=20Serializer=20=EC=84=A4=EC=A0=95?= =?UTF-8?q?=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../kotlin/com/swm/idle/domain/common/config/RedisConfig.kt | 2 ++ 1 file changed, 2 insertions(+) diff --git a/idle-domain/src/main/kotlin/com/swm/idle/domain/common/config/RedisConfig.kt b/idle-domain/src/main/kotlin/com/swm/idle/domain/common/config/RedisConfig.kt index c913bbe6..984f9a5f 100644 --- a/idle-domain/src/main/kotlin/com/swm/idle/domain/common/config/RedisConfig.kt +++ b/idle-domain/src/main/kotlin/com/swm/idle/domain/common/config/RedisConfig.kt @@ -42,6 +42,8 @@ class RedisConfig( connectionFactory = redisConnectionFactory!! keySerializer = StringRedisSerializer() valueSerializer = serializer + hashKeySerializer = StringRedisSerializer() + hashValueSerializer = serializer } } From be7b8521baffc226f5ef974f8f6ea0dc09a74347 Mon Sep 17 00:00:00 2001 From: wonjunYou Date: Wed, 27 Nov 2024 16:42:49 +0900 Subject: [PATCH 6/8] =?UTF-8?q?[IDLE-476]=20json=20=EC=97=AD=EC=A7=81?= =?UTF-8?q?=EB=A0=AC=ED=99=94=20=EC=8B=9C,=20=ED=8A=B9=EC=88=98=EB=AC=B8?= =?UTF-8?q?=EC=9E=90=20=ED=97=88=EC=9A=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../kotlin/com/swm/idle/domain/common/config/RedisConfig.kt | 2 ++ 1 file changed, 2 insertions(+) diff --git a/idle-domain/src/main/kotlin/com/swm/idle/domain/common/config/RedisConfig.kt b/idle-domain/src/main/kotlin/com/swm/idle/domain/common/config/RedisConfig.kt index 984f9a5f..580298af 100644 --- a/idle-domain/src/main/kotlin/com/swm/idle/domain/common/config/RedisConfig.kt +++ b/idle-domain/src/main/kotlin/com/swm/idle/domain/common/config/RedisConfig.kt @@ -1,5 +1,6 @@ package com.swm.idle.domain.common.config +import com.fasterxml.jackson.core.json.JsonReadFeature import com.fasterxml.jackson.databind.ObjectMapper import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule import com.fasterxml.jackson.module.kotlin.KotlinModule @@ -50,6 +51,7 @@ class RedisConfig( private val objectMapper = ObjectMapper().apply { registerModule(KotlinModule.Builder().build()) registerModule(JavaTimeModule()) + enable(JsonReadFeature.ALLOW_UNESCAPED_CONTROL_CHARS.mappedFeature()) } } From d2e064b29799754c97752326cd179709e090eb8a Mon Sep 17 00:00:00 2001 From: wonjunYou Date: Wed, 27 Nov 2024 16:51:08 +0900 Subject: [PATCH 7/8] =?UTF-8?q?[IDLE-476]=20websocket=20stomp=20=EC=97=94?= =?UTF-8?q?=EB=93=9C=ED=8F=AC=EC=9D=B8=ED=8A=B8=20=EB=85=B8=EC=B6=9C=20?= =?UTF-8?q?=EC=84=A4=EC=A0=95=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/swm/idle/presentation/chat/config/WebSocketConfig.kt | 5 ----- 1 file changed, 5 deletions(-) diff --git a/idle-presentation/src/main/kotlin/com/swm/idle/presentation/chat/config/WebSocketConfig.kt b/idle-presentation/src/main/kotlin/com/swm/idle/presentation/chat/config/WebSocketConfig.kt index bd60e8a2..79dc4da2 100644 --- a/idle-presentation/src/main/kotlin/com/swm/idle/presentation/chat/config/WebSocketConfig.kt +++ b/idle-presentation/src/main/kotlin/com/swm/idle/presentation/chat/config/WebSocketConfig.kt @@ -11,11 +11,6 @@ import org.springframework.web.socket.config.annotation.WebSocketMessageBrokerCo class WebSocketConfig : WebSocketMessageBrokerConfigurer { override fun registerStompEndpoints(registry: StompEndpointRegistry) { - registry - .addEndpoint("/websocket") - .setAllowedOriginPatterns("*") - .withSockJS() - registry .addEndpoint("/websocket") .setAllowedOriginPatterns("*") From a81257c3e35fdc0622bcd69f28f632f69ac58e7f Mon Sep 17 00:00:00 2001 From: wonjunYou Date: Wed, 27 Nov 2024 17:07:21 +0900 Subject: [PATCH 8/8] =?UTF-8?q?[IDLE-476]=20=EC=B1=84=ED=8C=85=20=EB=A9=94?= =?UTF-8?q?=EC=84=B8=EC=A7=80=20=EA=B8=B8=EC=9D=B4=20=EC=A0=95=EC=B1=85=20?= =?UTF-8?q?=EC=A0=81=EC=9A=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/swm/idle/domain/chat/entity/jpa/ChatMessage.kt | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/idle-domain/src/main/kotlin/com/swm/idle/domain/chat/entity/jpa/ChatMessage.kt b/idle-domain/src/main/kotlin/com/swm/idle/domain/chat/entity/jpa/ChatMessage.kt index e4d4ef35..4120be0e 100644 --- a/idle-domain/src/main/kotlin/com/swm/idle/domain/chat/entity/jpa/ChatMessage.kt +++ b/idle-domain/src/main/kotlin/com/swm/idle/domain/chat/entity/jpa/ChatMessage.kt @@ -2,7 +2,6 @@ package com.swm.idle.domain.chat.entity.jpa import com.swm.idle.domain.chat.enums.ContentType import com.swm.idle.domain.chat.enums.SenderType -//import com.swm.idle.domain.chat.vo.Content import com.swm.idle.domain.common.entity.BaseEntity import jakarta.persistence.Column import jakarta.persistence.Entity @@ -43,6 +42,12 @@ class ChatMessage( data class Content( val type: ContentType, val value: String, - ) + ) { + + init { + require(value.isNotBlank()) { "채팅 메세지는 최소 1자 이상 입력해 주셔야 합니다." } + require(value.length <= 500) { "채팅 메세지는 500자를 초과할 수 없습니다." } + } + } }