From dff709e45a498f79ddd295c0270b757bb86854c1 Mon Sep 17 00:00:00 2001 From: sunwoong Date: Sun, 25 Aug 2024 06:27:29 +0900 Subject: [PATCH 1/4] =?UTF-8?q?DRAW-263=20feat:=20=EB=A7=88=ED=94=BC?= =?UTF-8?q?=EC=95=84=20=EA=B2=8C=EC=9E=84=20=EC=A0=95=EB=B3=B4=20RoomId=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../message/response/MafiaPhaseMessengerImpl.kt | 16 +++++++++++----- .../response/dto/phase/MafiaGameInfoMessage.kt | 2 ++ 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/app/websocket/src/main/kotlin/com/xorker/draw/websocket/message/response/MafiaPhaseMessengerImpl.kt b/app/websocket/src/main/kotlin/com/xorker/draw/websocket/message/response/MafiaPhaseMessengerImpl.kt index ed312bd5..29b6192e 100644 --- a/app/websocket/src/main/kotlin/com/xorker/draw/websocket/message/response/MafiaPhaseMessengerImpl.kt +++ b/app/websocket/src/main/kotlin/com/xorker/draw/websocket/message/response/MafiaPhaseMessengerImpl.kt @@ -6,6 +6,7 @@ import com.xorker.draw.mafia.MafiaKeyword import com.xorker.draw.mafia.MafiaPhase import com.xorker.draw.mafia.MafiaPhaseMessenger import com.xorker.draw.mafia.MafiaPlayer +import com.xorker.draw.room.RoomId import com.xorker.draw.user.UserId import com.xorker.draw.websocket.SessionMessage import com.xorker.draw.websocket.broker.WebSocketBroadcaster @@ -55,7 +56,7 @@ internal class MafiaPhaseMessengerImpl( is MafiaPhase.Ready -> MafiaPhaseReadyMessage( MafiaPhaseReadyBody( startTime = phase.job.startTime, - mafiaGameInfo = generateMafiaGameInfoMessage(phase.mafiaPlayer, phase.turnList, phase.keyword, gameOption), + mafiaGameInfo = generateMafiaGameInfoMessage(this.room.id, phase.mafiaPlayer, phase.turnList, phase.keyword, gameOption), ), ) @@ -66,7 +67,7 @@ internal class MafiaPhaseMessengerImpl( startTurnTime = phase.job.startTime, draw = phase.getDraw(), currentDraw = phase.getCurrentDraw(), - mafiaGameInfo = generateMafiaGameInfoMessage(phase.mafiaPlayer, phase.turnList, phase.keyword, gameOption), + mafiaGameInfo = generateMafiaGameInfoMessage(this.room.id, phase.mafiaPlayer, phase.turnList, phase.keyword, gameOption), ), ) @@ -74,7 +75,8 @@ internal class MafiaPhaseMessengerImpl( MafiaPhaseVoteBody( startTime = phase.job.startTime, mafiaGameInfo = if (isOrigin.not()) { - generateMafiaGameInfoMessage(phase.mafiaPlayer, phase.turnList, phase.keyword, gameOption) + val room = this.room + generateMafiaGameInfoMessage(room.id, phase.mafiaPlayer, phase.turnList, phase.keyword, gameOption) } else { null }, @@ -87,7 +89,8 @@ internal class MafiaPhaseMessengerImpl( MafiaPhaseInferAnswerBody( startTime = phase.job.startTime, mafiaGameInfo = if (isOrigin.not()) { - generateMafiaGameInfoMessage(phase.mafiaPlayer, phase.turnList, phase.keyword, gameOption) + val room = this.room + generateMafiaGameInfoMessage(room.id, phase.mafiaPlayer, phase.turnList, phase.keyword, gameOption) } else { null }, @@ -100,7 +103,8 @@ internal class MafiaPhaseMessengerImpl( MafiaPhaseEndBody( startTime = phase.job.startTime, mafiaGameInfo = if (isOrigin.not()) { - generateMafiaGameInfoMessage(phase.mafiaPlayer, phase.turnList, phase.keyword, gameOption) + val room = this.room + generateMafiaGameInfoMessage(room.id, phase.mafiaPlayer, phase.turnList, phase.keyword, gameOption) } else { null }, @@ -114,6 +118,7 @@ internal class MafiaPhaseMessengerImpl( } private fun generateMafiaGameInfoMessage( + roomId: RoomId, mafiaPlayer: MafiaPlayer, turnList: List, keyword: MafiaKeyword, @@ -121,6 +126,7 @@ internal class MafiaPhaseMessengerImpl( ): MafiaGameInfoMessage = MafiaGameInfoMessage( MafiaGameInfoBody( + roomId = roomId, mafiaUserId = mafiaPlayer.userId, turnList = turnList, category = keyword.category, diff --git a/app/websocket/src/main/kotlin/com/xorker/draw/websocket/message/response/dto/phase/MafiaGameInfoMessage.kt b/app/websocket/src/main/kotlin/com/xorker/draw/websocket/message/response/dto/phase/MafiaGameInfoMessage.kt index f7809f13..deaacd7d 100644 --- a/app/websocket/src/main/kotlin/com/xorker/draw/websocket/message/response/dto/phase/MafiaGameInfoMessage.kt +++ b/app/websocket/src/main/kotlin/com/xorker/draw/websocket/message/response/dto/phase/MafiaGameInfoMessage.kt @@ -2,6 +2,7 @@ package com.xorker.draw.websocket.message.response.dto.phase import com.xorker.draw.mafia.MafiaGameOption import com.xorker.draw.mafia.MafiaPlayer +import com.xorker.draw.room.RoomId import com.xorker.draw.user.UserId import com.xorker.draw.websocket.ResponseAction import com.xorker.draw.websocket.SessionMessage @@ -14,6 +15,7 @@ data class MafiaGameInfoMessage( } data class MafiaGameInfoBody( + val roomId: RoomId, val mafiaUserId: UserId, val turnList: List, val category: String, From f03dca47605258852b43e6557308182b00991a55 Mon Sep 17 00:00:00 2001 From: HoYeon Lee Date: Sun, 25 Aug 2024 06:49:30 +0900 Subject: [PATCH 2/4] =?UTF-8?q?DRAW-262=20fix:=20Api=20Logging=20Filter=20?= =?UTF-8?q?UrlFilter=20=EC=A0=81=EC=9A=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../xorker/draw/log/ApiLoggerFilterConfig.kt | 20 +++++++++++++++++++ .../com/xorker/draw/log/ApiLoggingFilter.kt | 5 ----- 2 files changed, 20 insertions(+), 5 deletions(-) create mode 100644 app/api/src/main/kotlin/com/xorker/draw/log/ApiLoggerFilterConfig.kt diff --git a/app/api/src/main/kotlin/com/xorker/draw/log/ApiLoggerFilterConfig.kt b/app/api/src/main/kotlin/com/xorker/draw/log/ApiLoggerFilterConfig.kt new file mode 100644 index 00000000..72a083d2 --- /dev/null +++ b/app/api/src/main/kotlin/com/xorker/draw/log/ApiLoggerFilterConfig.kt @@ -0,0 +1,20 @@ +package com.xorker.draw.log + +import org.springframework.boot.web.servlet.FilterRegistrationBean +import org.springframework.context.annotation.Bean +import org.springframework.context.annotation.Configuration +import org.springframework.core.Ordered + +@Configuration +class ApiLoggerFilterConfig { + @Bean + fun apiLogFilter(filter: ApiLoggingFilter): FilterRegistrationBean { + val bean = FilterRegistrationBean() + + bean.filter = filter + bean.order = Ordered.HIGHEST_PRECEDENCE + bean.urlPatterns = listOf("/api/*") + + return bean + } +} diff --git a/app/api/src/main/kotlin/com/xorker/draw/log/ApiLoggingFilter.kt b/app/api/src/main/kotlin/com/xorker/draw/log/ApiLoggingFilter.kt index 16abe8ce..915c22bd 100644 --- a/app/api/src/main/kotlin/com/xorker/draw/log/ApiLoggingFilter.kt +++ b/app/api/src/main/kotlin/com/xorker/draw/log/ApiLoggingFilter.kt @@ -8,19 +8,14 @@ import jakarta.servlet.Filter import jakarta.servlet.FilterChain import jakarta.servlet.ServletRequest import jakarta.servlet.ServletResponse -import jakarta.servlet.annotation.WebFilter import jakarta.servlet.http.HttpServletRequest import jakarta.servlet.http.HttpServletResponse import org.slf4j.MDC -import org.springframework.core.Ordered -import org.springframework.core.annotation.Order import org.springframework.stereotype.Component import org.springframework.web.util.ContentCachingRequestWrapper import org.springframework.web.util.ContentCachingResponseWrapper @Component -@WebFilter(urlPatterns = ["/api/*"]) -@Order(Ordered.HIGHEST_PRECEDENCE) class ApiLoggingFilter( private val objectMapper: ObjectMapper, ) : Filter { From 1312f1a31c2ece0ce3867de9b6d501b2a4755d66 Mon Sep 17 00:00:00 2001 From: sunwoong Date: Sun, 25 Aug 2024 20:48:42 +0900 Subject: [PATCH 3/4] =?UTF-8?q?DRAW-264=20feat:=20=EB=B0=A9=20=EB=9E=9C?= =?UTF-8?q?=EB=8D=A4=20=EB=A7=A4=EC=B9=AD=20=EC=97=AC=EB=B6=80=20=ED=95=84?= =?UTF-8?q?=EB=93=9C=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../response/MafiaPhaseMessengerImpl.kt | 52 +++++++++++++++---- .../dto/phase/MafiaGameInfoMessage.kt | 1 + .../xorker/draw/mafia/MafiaGameRoomService.kt | 22 +++++--- .../main/kotlin/com/xorker/draw/room/Room.kt | 7 ++- 4 files changed, 63 insertions(+), 19 deletions(-) diff --git a/app/websocket/src/main/kotlin/com/xorker/draw/websocket/message/response/MafiaPhaseMessengerImpl.kt b/app/websocket/src/main/kotlin/com/xorker/draw/websocket/message/response/MafiaPhaseMessengerImpl.kt index 29b6192e..8fbddc24 100644 --- a/app/websocket/src/main/kotlin/com/xorker/draw/websocket/message/response/MafiaPhaseMessengerImpl.kt +++ b/app/websocket/src/main/kotlin/com/xorker/draw/websocket/message/response/MafiaPhaseMessengerImpl.kt @@ -49,14 +49,21 @@ internal class MafiaPhaseMessengerImpl( MafiaPhaseWaitBody( room.id, room.players.map { it.toResponse(room.owner) }.toList(), - this.gameOption.toResponse(), + gameOption.toResponse(), ), ) is MafiaPhase.Ready -> MafiaPhaseReadyMessage( MafiaPhaseReadyBody( startTime = phase.job.startTime, - mafiaGameInfo = generateMafiaGameInfoMessage(this.room.id, phase.mafiaPlayer, phase.turnList, phase.keyword, gameOption), + mafiaGameInfo = generateMafiaGameInfoMessage( + roomId = room.id, + isRandomMatching = room.isRandomMatching, + mafiaPlayer = phase.mafiaPlayer, + turnList = phase.turnList, + keyword = phase.keyword, + gameOption = gameOption, + ), ), ) @@ -67,7 +74,14 @@ internal class MafiaPhaseMessengerImpl( startTurnTime = phase.job.startTime, draw = phase.getDraw(), currentDraw = phase.getCurrentDraw(), - mafiaGameInfo = generateMafiaGameInfoMessage(this.room.id, phase.mafiaPlayer, phase.turnList, phase.keyword, gameOption), + mafiaGameInfo = generateMafiaGameInfoMessage( + roomId = room.id, + isRandomMatching = room.isRandomMatching, + mafiaPlayer = phase.mafiaPlayer, + turnList = phase.turnList, + keyword = phase.keyword, + gameOption = gameOption, + ), ), ) @@ -75,8 +89,14 @@ internal class MafiaPhaseMessengerImpl( MafiaPhaseVoteBody( startTime = phase.job.startTime, mafiaGameInfo = if (isOrigin.not()) { - val room = this.room - generateMafiaGameInfoMessage(room.id, phase.mafiaPlayer, phase.turnList, phase.keyword, gameOption) + generateMafiaGameInfoMessage( + roomId = room.id, + isRandomMatching = room.isRandomMatching, + mafiaPlayer = phase.mafiaPlayer, + turnList = phase.turnList, + keyword = phase.keyword, + gameOption = gameOption, + ) } else { null }, @@ -89,8 +109,14 @@ internal class MafiaPhaseMessengerImpl( MafiaPhaseInferAnswerBody( startTime = phase.job.startTime, mafiaGameInfo = if (isOrigin.not()) { - val room = this.room - generateMafiaGameInfoMessage(room.id, phase.mafiaPlayer, phase.turnList, phase.keyword, gameOption) + generateMafiaGameInfoMessage( + roomId = room.id, + isRandomMatching = room.isRandomMatching, + mafiaPlayer = phase.mafiaPlayer, + turnList = phase.turnList, + keyword = phase.keyword, + gameOption = gameOption, + ) } else { null }, @@ -103,8 +129,14 @@ internal class MafiaPhaseMessengerImpl( MafiaPhaseEndBody( startTime = phase.job.startTime, mafiaGameInfo = if (isOrigin.not()) { - val room = this.room - generateMafiaGameInfoMessage(room.id, phase.mafiaPlayer, phase.turnList, phase.keyword, gameOption) + generateMafiaGameInfoMessage( + roomId = room.id, + isRandomMatching = room.isRandomMatching, + mafiaPlayer = phase.mafiaPlayer, + turnList = phase.turnList, + keyword = phase.keyword, + gameOption = gameOption, + ) } else { null }, @@ -119,6 +151,7 @@ internal class MafiaPhaseMessengerImpl( private fun generateMafiaGameInfoMessage( roomId: RoomId, + isRandomMatching: Boolean, mafiaPlayer: MafiaPlayer, turnList: List, keyword: MafiaKeyword, @@ -127,6 +160,7 @@ internal class MafiaPhaseMessengerImpl( MafiaGameInfoMessage( MafiaGameInfoBody( roomId = roomId, + isRandomMatching = isRandomMatching, mafiaUserId = mafiaPlayer.userId, turnList = turnList, category = keyword.category, diff --git a/app/websocket/src/main/kotlin/com/xorker/draw/websocket/message/response/dto/phase/MafiaGameInfoMessage.kt b/app/websocket/src/main/kotlin/com/xorker/draw/websocket/message/response/dto/phase/MafiaGameInfoMessage.kt index deaacd7d..9f09b408 100644 --- a/app/websocket/src/main/kotlin/com/xorker/draw/websocket/message/response/dto/phase/MafiaGameInfoMessage.kt +++ b/app/websocket/src/main/kotlin/com/xorker/draw/websocket/message/response/dto/phase/MafiaGameInfoMessage.kt @@ -16,6 +16,7 @@ data class MafiaGameInfoMessage( data class MafiaGameInfoBody( val roomId: RoomId, + val isRandomMatching: Boolean, val mafiaUserId: UserId, val turnList: List, val category: String, diff --git a/core/src/main/kotlin/com/xorker/draw/mafia/MafiaGameRoomService.kt b/core/src/main/kotlin/com/xorker/draw/mafia/MafiaGameRoomService.kt index 6aca6d22..18ee6a2f 100644 --- a/core/src/main/kotlin/com/xorker/draw/mafia/MafiaGameRoomService.kt +++ b/core/src/main/kotlin/com/xorker/draw/mafia/MafiaGameRoomService.kt @@ -44,7 +44,7 @@ internal class MafiaGameRoomService( if (gameInfo == null) { val player = MafiaPlayer(user.id, user.name, generateColor(null)) - gameInfo = createGameInfo(session, locale, player) + gameInfo = createGameInfo(session, locale, player, true) } else { val room = gameInfo.room @@ -108,22 +108,28 @@ internal class MafiaGameRoomService( .first() } - private fun createGameInfo(session: Session, locale: String, player: MafiaPlayer): MafiaGameInfo { - val room = createRoom(session, locale, player) + private fun createGameInfo(session: Session, locale: String, player: MafiaPlayer, isRandomMatching: Boolean = false): MafiaGameInfo { + val room = createRoom(session, locale, player, isRandomMatching) return MafiaGameInfo( - room, - MafiaPhase.Wait, - MafiaGameOption(), + room = room, + phase = MafiaPhase.Wait, + gameOption = MafiaGameOption(), ) } - private fun createRoom(session: Session, locale: String, player: MafiaPlayer): Room { + private fun createRoom(session: Session, locale: String, player: MafiaPlayer, isRandomMatching: Boolean): Room { val language = locale.lowercase() if (language !in languages) { throw InvalidRequestValueException } - val room = Room(session.roomId, language, player, 10) + val room = Room( + id = session.roomId, + locale = language, + owner = player, + maxMemberNum = 10, + isRandomMatching = isRandomMatching, + ) return room } diff --git a/domain/src/main/kotlin/com/xorker/draw/room/Room.kt b/domain/src/main/kotlin/com/xorker/draw/room/Room.kt index eae0be59..3829a8ca 100644 --- a/domain/src/main/kotlin/com/xorker/draw/room/Room.kt +++ b/domain/src/main/kotlin/com/xorker/draw/room/Room.kt @@ -13,6 +13,7 @@ interface Room

{ var owner: P val maxMemberNum: Int val players: List

+ val isRandomMatching: Boolean fun size(): Int = players.size fun isEmpty(): Boolean = size() == 0 @@ -31,7 +32,8 @@ fun

Room( owner: P, maxMemberNum: Int, players: MutableList

= mutableListOf(owner), -): Room

= RoomImpl(id, locale, owner, maxMemberNum, players) + isRandomMatching: Boolean = false, +): Room

= RoomImpl(id, locale, owner, maxMemberNum, players, isRandomMatching) class RoomImpl

( override val id: RoomId, @@ -39,6 +41,7 @@ class RoomImpl

( override var owner: P, override val maxMemberNum: Int, private val _players: MutableList

= mutableListOf(owner), + override val isRandomMatching: Boolean, ) : Room

{ override val players: List

= _players @@ -64,5 +67,5 @@ class RoomImpl

( _players.clear() } - override fun copy(): Room

= RoomImpl(id, locale, owner, maxMemberNum, _players) + override fun copy(): Room

= RoomImpl(id, locale, owner, maxMemberNum, _players, isRandomMatching) } From 5abab6231d41368d98a612226dea4131e89f56aa Mon Sep 17 00:00:00 2001 From: sunwoong Date: Mon, 26 Aug 2024 18:20:56 +0900 Subject: [PATCH 4/4] =?UTF-8?q?DRAW-265=20fix:=20=EB=A7=88=ED=94=BC?= =?UTF-8?q?=EC=95=84=20=EC=A0=95=EB=8B=B5=20=ED=8C=90=EB=B3=84=20=EB=A1=9C?= =?UTF-8?q?=EC=A7=81=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../xorker/draw/mafia/phase/MafiaPhaseEndGameProcessor.kt | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/core/src/main/kotlin/com/xorker/draw/mafia/phase/MafiaPhaseEndGameProcessor.kt b/core/src/main/kotlin/com/xorker/draw/mafia/phase/MafiaPhaseEndGameProcessor.kt index d9358d47..87efdabc 100644 --- a/core/src/main/kotlin/com/xorker/draw/mafia/phase/MafiaPhaseEndGameProcessor.kt +++ b/core/src/main/kotlin/com/xorker/draw/mafia/phase/MafiaPhaseEndGameProcessor.kt @@ -101,7 +101,10 @@ internal class MafiaPhaseEndGameProcessor( val keyword = endPhase.keyword endPhase.isMafiaWin = endPhase.answer?.let { - keyword.answer.lowercase() == it.lowercase() // TODO 동의어 처리 + val trimmedAnswer = keyword.answer.replace(" ", "") + val trimmedMafiaAnswer = it.replace(" ", "") + + trimmedAnswer.lowercase() == trimmedMafiaAnswer.lowercase() // TODO 동의어 처리 } ?: false } }