From 2412286c9c456873dedb0135f65bf025efaf98ba Mon Sep 17 00:00:00 2001 From: Park - Jeonghwan <990706leo@gmail.com> Date: Mon, 13 May 2024 23:07:29 +0900 Subject: [PATCH 01/11] =?UTF-8?q?feat(domain):=20GroupChatMessage=20?= =?UTF-8?q?=EC=A1=B0=ED=9A=8C=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../dto/command/GroupChatGetMessageCommand.kt | 10 +++++++ .../service/GroupChatGetMessageCommander.kt | 28 +++++++++++++++++++ .../port/in/GetGroupChatMessageUseCase.kt | 10 +++++++ .../port/out/GetGroupChatMessagePort.kt | 10 +++++++ 4 files changed, 58 insertions(+) create mode 100644 domain/src/main/kotlin/gloddy/groupChat/dto/command/GroupChatGetMessageCommand.kt create mode 100644 domain/src/main/kotlin/gloddy/groupChat/service/GroupChatGetMessageCommander.kt create mode 100644 domain/src/main/kotlin/gloddy/port/in/GetGroupChatMessageUseCase.kt create mode 100644 domain/src/main/kotlin/gloddy/port/out/GetGroupChatMessagePort.kt diff --git a/domain/src/main/kotlin/gloddy/groupChat/dto/command/GroupChatGetMessageCommand.kt b/domain/src/main/kotlin/gloddy/groupChat/dto/command/GroupChatGetMessageCommand.kt new file mode 100644 index 0000000..9cf73cd --- /dev/null +++ b/domain/src/main/kotlin/gloddy/groupChat/dto/command/GroupChatGetMessageCommand.kt @@ -0,0 +1,10 @@ +package gloddy.groupChat.dto.command + +import gloddy.util.CursorRequest +import java.util.* + +data class GroupChatGetMessageCommand( + val userId: Long, + val chatId: UUID, + val cursorRequest: CursorRequest +) diff --git a/domain/src/main/kotlin/gloddy/groupChat/service/GroupChatGetMessageCommander.kt b/domain/src/main/kotlin/gloddy/groupChat/service/GroupChatGetMessageCommander.kt new file mode 100644 index 0000000..30b18df --- /dev/null +++ b/domain/src/main/kotlin/gloddy/groupChat/service/GroupChatGetMessageCommander.kt @@ -0,0 +1,28 @@ +package gloddy.groupChat.service + +import gloddy.groupChat.GroupChatMessage +import gloddy.groupChat.dto.command.GroupChatGetMessageCommand +import gloddy.port.`in`.GetGroupChatMessageUseCase +import gloddy.port.out.GetGroupChatMessagePort +import gloddy.util.CursorRequest +import gloddy.util.PageCursor + +class GroupChatGetMessageCommander(private val getGroupChatMessagePort: GetGroupChatMessagePort) : GetGroupChatMessageUseCase { + + override fun getPosts(command: GroupChatGetMessageCommand): PageCursor { + var posts = findAllBy(command) + var nextKey = posts.stream() + .mapToLong(GroupChatMessage::sequenceId) + .min() + .orElse(CursorRequest.NONE_KEY) + return PageCursor(command.cursorRequest.next(nextKey), posts.size, posts) + } + + private fun findAllBy(command: GroupChatGetMessageCommand): List { + return if (command.cursorRequest.hasKey()) { + getGroupChatMessagePort.findWithKey(command) + } else { + getGroupChatMessagePort.findWithoutKey(command) + } + } +} \ No newline at end of file diff --git a/domain/src/main/kotlin/gloddy/port/in/GetGroupChatMessageUseCase.kt b/domain/src/main/kotlin/gloddy/port/in/GetGroupChatMessageUseCase.kt new file mode 100644 index 0000000..5b44582 --- /dev/null +++ b/domain/src/main/kotlin/gloddy/port/in/GetGroupChatMessageUseCase.kt @@ -0,0 +1,10 @@ +package gloddy.port.`in` + +import gloddy.groupChat.GroupChatMessage +import gloddy.groupChat.dto.command.GroupChatGetMessageCommand +import gloddy.util.PageCursor + +interface GetGroupChatMessageUseCase { + + fun getPosts(groupChatGetMessageCommand: GroupChatGetMessageCommand): PageCursor +} \ No newline at end of file diff --git a/domain/src/main/kotlin/gloddy/port/out/GetGroupChatMessagePort.kt b/domain/src/main/kotlin/gloddy/port/out/GetGroupChatMessagePort.kt new file mode 100644 index 0000000..0160307 --- /dev/null +++ b/domain/src/main/kotlin/gloddy/port/out/GetGroupChatMessagePort.kt @@ -0,0 +1,10 @@ +package gloddy.port.out + +import gloddy.groupChat.GroupChatMessage +import gloddy.groupChat.dto.command.GroupChatGetMessageCommand + +interface GetGroupChatMessagePort { + fun findWithoutKey(groupChatGetMessageCommand: GroupChatGetMessageCommand): List + + fun findWithKey(groupChatGetMessageCommand: GroupChatGetMessageCommand): List +} \ No newline at end of file From 12f82b3e1680822b5bb80592069073567a7ee1df Mon Sep 17 00:00:00 2001 From: Park - Jeonghwan <990706leo@gmail.com> Date: Mon, 13 May 2024 23:07:42 +0900 Subject: [PATCH 02/11] =?UTF-8?q?feat(domain):=20Cursor=20=EC=82=AC?= =?UTF-8?q?=EC=9A=A9=ED=95=98=EA=B8=B0=20=EC=9C=84=ED=95=9C=20=EC=BD=94?= =?UTF-8?q?=EB=93=9C=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/kotlin/gloddy/util/CursorRequest.kt | 18 ++++++++++++++++++ .../src/main/kotlin/gloddy/util/PageCursor.kt | 7 +++++++ 2 files changed, 25 insertions(+) create mode 100644 domain/src/main/kotlin/gloddy/util/CursorRequest.kt create mode 100644 domain/src/main/kotlin/gloddy/util/PageCursor.kt diff --git a/domain/src/main/kotlin/gloddy/util/CursorRequest.kt b/domain/src/main/kotlin/gloddy/util/CursorRequest.kt new file mode 100644 index 0000000..f8f6450 --- /dev/null +++ b/domain/src/main/kotlin/gloddy/util/CursorRequest.kt @@ -0,0 +1,18 @@ +package gloddy.util + + +data class CursorRequest( + val key: Long? +) { + companion object { + const val NONE_KEY: Long = -1L + } + + fun hasKey(): Boolean { + return key != null + } + + fun next(key: Long?): CursorRequest { + return CursorRequest(key) + } +} \ No newline at end of file diff --git a/domain/src/main/kotlin/gloddy/util/PageCursor.kt b/domain/src/main/kotlin/gloddy/util/PageCursor.kt new file mode 100644 index 0000000..7a93024 --- /dev/null +++ b/domain/src/main/kotlin/gloddy/util/PageCursor.kt @@ -0,0 +1,7 @@ +package gloddy.util + +data class PageCursor( + val nextCursorRequest: CursorRequest, + val size: Int, + val body: List +) \ No newline at end of file From 90670a02969a357ddc871ad8a3c4020c4b0199b7 Mon Sep 17 00:00:00 2001 From: Park - Jeonghwan <990706leo@gmail.com> Date: Mon, 13 May 2024 23:08:20 +0900 Subject: [PATCH 03/11] =?UTF-8?q?feat(storage):=20=EC=BB=A4=EC=84=9C=20?= =?UTF-8?q?=EA=B8=B0=EB=B0=98=20=ED=8E=98=EC=9D=B4=EC=A7=80=EB=84=A4?= =?UTF-8?q?=EC=9D=B4=EC=85=98=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../adapter/GroupChatMessageCommandAdapter.kt | 28 ++++++ .../repository/GroupChatMessageRepository.kt | 58 +++++++++++++ .../GroupChatMessageRepositoryTest.kt | 86 +++++++++++++++++++ 3 files changed, 172 insertions(+) create mode 100644 storage/src/main/kotlin/gloddy/adapter/GroupChatMessageCommandAdapter.kt create mode 100644 storage/src/main/kotlin/gloddy/persistence/repository/GroupChatMessageRepository.kt create mode 100644 storage/src/test/kotlin/gloddy/groupChat/GroupChatMessageRepositoryTest.kt diff --git a/storage/src/main/kotlin/gloddy/adapter/GroupChatMessageCommandAdapter.kt b/storage/src/main/kotlin/gloddy/adapter/GroupChatMessageCommandAdapter.kt new file mode 100644 index 0000000..080ae2e --- /dev/null +++ b/storage/src/main/kotlin/gloddy/adapter/GroupChatMessageCommandAdapter.kt @@ -0,0 +1,28 @@ +package gloddy.adapter + +import gloddy.groupChat.GroupChatMessage +import gloddy.groupChat.dto.command.GroupChatGetMessageCommand +import gloddy.persistence.repository.GroupChatMessageRepository +import gloddy.port.out.GetGroupChatMessagePort + +class GroupChatMessageCommandAdapter( + private val repository: GroupChatMessageRepository) + : GetGroupChatMessagePort { + + override fun findWithoutKey(command: GroupChatGetMessageCommand): List { + return repository.findAllByMemberIdAndOrderByIdDesc( + command.userId, + command.chatId + ) + } + + override fun findWithKey(command: GroupChatGetMessageCommand): List { + return repository.findAllByLessThanIdMemberIdAndOrderByIdDesc( + command.cursorRequest.key, + command.userId, + command.chatId + ) + } + + +} \ No newline at end of file diff --git a/storage/src/main/kotlin/gloddy/persistence/repository/GroupChatMessageRepository.kt b/storage/src/main/kotlin/gloddy/persistence/repository/GroupChatMessageRepository.kt new file mode 100644 index 0000000..8e419cd --- /dev/null +++ b/storage/src/main/kotlin/gloddy/persistence/repository/GroupChatMessageRepository.kt @@ -0,0 +1,58 @@ +package gloddy.persistence.repository + +import gloddy.groupChat.GroupChatMessage +import gloddy.groupChat.vo.MessageType +import org.springframework.jdbc.core.RowMapper +import org.springframework.jdbc.core.namedparam.MapSqlParameterSource +import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate +import java.time.LocalDateTime +import java.util.* + +class GroupChatMessageRepository(private val namedParameterJdbcTemplate: NamedParameterJdbcTemplate) { + + companion object { + private const val TABLE = "GroupChatMessage" + private val ROW_MAPPER: RowMapper = RowMapper { rs, rowNum -> + GroupChatMessage( + userId = rs.getLong("userId"), + chatId = rs.getObject("chatId", UUID::class.java), + messageType = MessageType.valueOf(rs.getString("messageType")), + content = rs.getString("content"), + createdAt = rs.getObject("createdAt", LocalDateTime::class.java) ?: LocalDateTime.now(), + deleted = rs.getBoolean("deleted"), + deletedAt = rs.getObject("deletedAt", LocalDateTime::class.java), + id = rs.getObject("id", UUID::class.java), + sequenceId = rs.getLong("sequenceId")) + } + } + + fun findAllByMemberIdAndOrderByIdDesc(userId: Long, chatId: UUID): List { + val sql = """ + SELECT * + FROM $TABLE as message + INNER JOIN GroupChatUser AS user + ON user.chatId = message.chatId + WHERE chatId = :chatId and user.createdAt < message.createdAt + ORDER BY sequenceId desc + """.trimIndent() + val params = MapSqlParameterSource() + .addValue("chatId", chatId) + + return namedParameterJdbcTemplate.query(sql, params, ROW_MAPPER) + } + + fun findAllByLessThanIdMemberIdAndOrderByIdDesc(sequenceId: Long?, userId: Long, chatId: UUID): List { + val sql = """ + SELECT * + FROM $TABLE + WHERE chatId = :chatId and sequenceId < :sequenceId + ORDER BY sequenceId desc + """.trimIndent() + val params = MapSqlParameterSource() + .addValue("sequenceId", sequenceId) + .addValue("chatId", chatId) + + return namedParameterJdbcTemplate.query(sql, params, ROW_MAPPER) + } + +} \ No newline at end of file diff --git a/storage/src/test/kotlin/gloddy/groupChat/GroupChatMessageRepositoryTest.kt b/storage/src/test/kotlin/gloddy/groupChat/GroupChatMessageRepositoryTest.kt new file mode 100644 index 0000000..cebf4f3 --- /dev/null +++ b/storage/src/test/kotlin/gloddy/groupChat/GroupChatMessageRepositoryTest.kt @@ -0,0 +1,86 @@ +package gloddy.groupChat + +import gloddy.groupChat.vo.MessageType +import gloddy.persistence.repository.GroupChatMessageRepository +import org.junit.jupiter.api.Assertions.assertEquals +import org.junit.jupiter.api.DisplayName +import org.junit.jupiter.api.Test +import org.junit.jupiter.api.extension.ExtendWith +import org.mockito.InjectMocks +import org.mockito.Mock +import org.mockito.junit.jupiter.MockitoExtension +import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate +import java.time.LocalDateTime +import java.util.* + +@ExtendWith(MockitoExtension::class) +class GroupChatMessageRepositoryTest { + + @Mock + private lateinit var namedParameterJdbcTemplate: NamedParameterJdbcTemplate + + @InjectMocks + private lateinit var groupChatMessageRepository: GroupChatMessageRepository + + + @Test + @DisplayName("커서가 없으면 날짜기준으로 입장 이후 메세지를 조회한다") + fun no_cursor() { + // Given + val userId = 123L + val chatId = UUID.randomUUID() + val expectedMessages = listOf( + GroupChatMessage( + userId = 1L, + chatId = chatId, + messageType = MessageType.USER_CONTENT, + content = "Message 1", + createdAt = LocalDateTime.now(), + deleted = false, + id = UUID.randomUUID(), + sequenceId = 1L + ), + GroupChatMessage( + userId = 2L, + chatId = chatId, + messageType = MessageType.USER_CONTENT, + content = "Message 2", + createdAt = LocalDateTime.now(), + deleted = false, + id = UUID.randomUUID(), + sequenceId = 2L + ) + ) + + // When + val result = groupChatMessageRepository.findAllByMemberIdAndOrderByIdDesc(userId, chatId) + + // Then + assertEquals(expectedMessages, result) + } + + @Test + @DisplayName("커서가 있으면 커서기준으로 이후 메세지를 조회한다") + fun cursor() { + + } + + @Test + @DisplayName("입장한 채팅방 메세지만 조회되어야 한다") + fun chatId() { + + } + + fun duplicateChat1Messages(cnt: Int) { + for (i in 0 until cnt) { + val newMessage = GroupChatMessage(1L, UUID(123456789L, 987654321L), MessageType.USER_CONTENT) + } + } + + fun duplicateChat2Messages(cnt: Int) { + for (i in 0 until cnt) { + val newMessages = GroupChatMessage(2L, UUID(987654321L, 123456789L), MessageType.USER_CONTENT) + } + } + +} \ No newline at end of file From 11051379d3630eb5f2659617377c00f62b217c81 Mon Sep 17 00:00:00 2001 From: Park - Jeonghwan <990706leo@gmail.com> Date: Wed, 15 May 2024 13:04:58 +0900 Subject: [PATCH 04/11] =?UTF-8?q?remove:=20=ED=85=8C=EC=8A=A4=ED=8A=B8=20?= =?UTF-8?q?=EC=82=AD=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../GroupChatMessageRepositoryTest.kt | 86 ------------------- 1 file changed, 86 deletions(-) delete mode 100644 storage/src/test/kotlin/gloddy/groupChat/GroupChatMessageRepositoryTest.kt diff --git a/storage/src/test/kotlin/gloddy/groupChat/GroupChatMessageRepositoryTest.kt b/storage/src/test/kotlin/gloddy/groupChat/GroupChatMessageRepositoryTest.kt deleted file mode 100644 index cebf4f3..0000000 --- a/storage/src/test/kotlin/gloddy/groupChat/GroupChatMessageRepositoryTest.kt +++ /dev/null @@ -1,86 +0,0 @@ -package gloddy.groupChat - -import gloddy.groupChat.vo.MessageType -import gloddy.persistence.repository.GroupChatMessageRepository -import org.junit.jupiter.api.Assertions.assertEquals -import org.junit.jupiter.api.DisplayName -import org.junit.jupiter.api.Test -import org.junit.jupiter.api.extension.ExtendWith -import org.mockito.InjectMocks -import org.mockito.Mock -import org.mockito.junit.jupiter.MockitoExtension -import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate -import java.time.LocalDateTime -import java.util.* - -@ExtendWith(MockitoExtension::class) -class GroupChatMessageRepositoryTest { - - @Mock - private lateinit var namedParameterJdbcTemplate: NamedParameterJdbcTemplate - - @InjectMocks - private lateinit var groupChatMessageRepository: GroupChatMessageRepository - - - @Test - @DisplayName("커서가 없으면 날짜기준으로 입장 이후 메세지를 조회한다") - fun no_cursor() { - // Given - val userId = 123L - val chatId = UUID.randomUUID() - val expectedMessages = listOf( - GroupChatMessage( - userId = 1L, - chatId = chatId, - messageType = MessageType.USER_CONTENT, - content = "Message 1", - createdAt = LocalDateTime.now(), - deleted = false, - id = UUID.randomUUID(), - sequenceId = 1L - ), - GroupChatMessage( - userId = 2L, - chatId = chatId, - messageType = MessageType.USER_CONTENT, - content = "Message 2", - createdAt = LocalDateTime.now(), - deleted = false, - id = UUID.randomUUID(), - sequenceId = 2L - ) - ) - - // When - val result = groupChatMessageRepository.findAllByMemberIdAndOrderByIdDesc(userId, chatId) - - // Then - assertEquals(expectedMessages, result) - } - - @Test - @DisplayName("커서가 있으면 커서기준으로 이후 메세지를 조회한다") - fun cursor() { - - } - - @Test - @DisplayName("입장한 채팅방 메세지만 조회되어야 한다") - fun chatId() { - - } - - fun duplicateChat1Messages(cnt: Int) { - for (i in 0 until cnt) { - val newMessage = GroupChatMessage(1L, UUID(123456789L, 987654321L), MessageType.USER_CONTENT) - } - } - - fun duplicateChat2Messages(cnt: Int) { - for (i in 0 until cnt) { - val newMessages = GroupChatMessage(2L, UUID(987654321L, 123456789L), MessageType.USER_CONTENT) - } - } - -} \ No newline at end of file From 4796e7b342990f218ed6a769120d6a27f5abb79e Mon Sep 17 00:00:00 2001 From: Park - Jeonghwan <990706leo@gmail.com> Date: Wed, 29 May 2024 19:16:31 +0900 Subject: [PATCH 05/11] =?UTF-8?q?refactor:=20=EB=A6=AC=EB=B7=B0=EB=B0=98?= =?UTF-8?q?=EC=98=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/GroupChatQueryController.kt | 21 +++++++++++++ .../dto/command/GroupChatGetMessageCommand.kt | 3 +- .../repository/GroupChatQueryRepository.kt | 11 +++++++ .../service/GroupChatGetMessageCommander.kt | 28 ----------------- .../groupChat/service/GroupChatReader.kt | 27 ++++++++++++++++ .../port/in/GetGroupChatMessageUseCase.kt | 10 ------ .../port/out/GetGroupChatMessagePort.kt | 10 ------ .../adapter/GroupChatMessageCommandAdapter.kt | 28 ----------------- .../GroupChatQueryAdapterRepository.kt | 31 +++++++++++++++++++ .../repository/GroupChatMessageRepository.kt | 6 ++-- 10 files changed, 94 insertions(+), 81 deletions(-) create mode 100644 api/src/main/kotlin/gloddy/controller/GroupChatQueryController.kt create mode 100644 domain/src/main/kotlin/gloddy/groupChat/repository/GroupChatQueryRepository.kt delete mode 100644 domain/src/main/kotlin/gloddy/groupChat/service/GroupChatGetMessageCommander.kt create mode 100644 domain/src/main/kotlin/gloddy/groupChat/service/GroupChatReader.kt delete mode 100644 domain/src/main/kotlin/gloddy/port/in/GetGroupChatMessageUseCase.kt delete mode 100644 domain/src/main/kotlin/gloddy/port/out/GetGroupChatMessagePort.kt delete mode 100644 storage/src/main/kotlin/gloddy/adapter/GroupChatMessageCommandAdapter.kt create mode 100644 storage/src/main/kotlin/gloddy/adapter/GroupChatQueryAdapterRepository.kt diff --git a/api/src/main/kotlin/gloddy/controller/GroupChatQueryController.kt b/api/src/main/kotlin/gloddy/controller/GroupChatQueryController.kt new file mode 100644 index 0000000..87a8859 --- /dev/null +++ b/api/src/main/kotlin/gloddy/controller/GroupChatQueryController.kt @@ -0,0 +1,21 @@ +package gloddy.controller + +import gloddy.groupChat.GroupChatMessage +import gloddy.groupChat.dto.command.GroupChatGetMessageCommand +import gloddy.groupChat.service.GroupChatReader +import gloddy.util.CursorRequest +import gloddy.util.PageCursor +import org.springframework.web.bind.annotation.GetMapping +import org.springframework.web.bind.annotation.PathVariable +import org.springframework.web.bind.annotation.RequestBody + +class GroupChatQueryController(private val groupChatReader: GroupChatReader) { + + @GetMapping("group-chat/{groupId}/messages") + fun getGroupChatMessages(@PathVariable("groupId") groupId:Long, + @RequestBody cursorRequest: CursorRequest) + : PageCursor{ + + return groupChatReader.getMessages(groupId, cursorRequest) + } +} \ No newline at end of file diff --git a/domain/src/main/kotlin/gloddy/groupChat/dto/command/GroupChatGetMessageCommand.kt b/domain/src/main/kotlin/gloddy/groupChat/dto/command/GroupChatGetMessageCommand.kt index 9cf73cd..ba3cd5b 100644 --- a/domain/src/main/kotlin/gloddy/groupChat/dto/command/GroupChatGetMessageCommand.kt +++ b/domain/src/main/kotlin/gloddy/groupChat/dto/command/GroupChatGetMessageCommand.kt @@ -4,7 +4,6 @@ import gloddy.util.CursorRequest import java.util.* data class GroupChatGetMessageCommand( - val userId: Long, - val chatId: UUID, + val groupId: Long, val cursorRequest: CursorRequest ) diff --git a/domain/src/main/kotlin/gloddy/groupChat/repository/GroupChatQueryRepository.kt b/domain/src/main/kotlin/gloddy/groupChat/repository/GroupChatQueryRepository.kt new file mode 100644 index 0000000..1abab03 --- /dev/null +++ b/domain/src/main/kotlin/gloddy/groupChat/repository/GroupChatQueryRepository.kt @@ -0,0 +1,11 @@ +package gloddy.groupChat.repository + +import gloddy.groupChat.GroupChatMessage +import gloddy.groupChat.dto.command.GroupChatGetMessageCommand +import gloddy.util.CursorRequest + +interface GroupChatQueryRepository { + fun findWithoutKey(groupId: Long): List + + fun findWithKey(groupId: Long, cursorRequest: CursorRequest): List +} \ No newline at end of file diff --git a/domain/src/main/kotlin/gloddy/groupChat/service/GroupChatGetMessageCommander.kt b/domain/src/main/kotlin/gloddy/groupChat/service/GroupChatGetMessageCommander.kt deleted file mode 100644 index 30b18df..0000000 --- a/domain/src/main/kotlin/gloddy/groupChat/service/GroupChatGetMessageCommander.kt +++ /dev/null @@ -1,28 +0,0 @@ -package gloddy.groupChat.service - -import gloddy.groupChat.GroupChatMessage -import gloddy.groupChat.dto.command.GroupChatGetMessageCommand -import gloddy.port.`in`.GetGroupChatMessageUseCase -import gloddy.port.out.GetGroupChatMessagePort -import gloddy.util.CursorRequest -import gloddy.util.PageCursor - -class GroupChatGetMessageCommander(private val getGroupChatMessagePort: GetGroupChatMessagePort) : GetGroupChatMessageUseCase { - - override fun getPosts(command: GroupChatGetMessageCommand): PageCursor { - var posts = findAllBy(command) - var nextKey = posts.stream() - .mapToLong(GroupChatMessage::sequenceId) - .min() - .orElse(CursorRequest.NONE_KEY) - return PageCursor(command.cursorRequest.next(nextKey), posts.size, posts) - } - - private fun findAllBy(command: GroupChatGetMessageCommand): List { - return if (command.cursorRequest.hasKey()) { - getGroupChatMessagePort.findWithKey(command) - } else { - getGroupChatMessagePort.findWithoutKey(command) - } - } -} \ No newline at end of file diff --git a/domain/src/main/kotlin/gloddy/groupChat/service/GroupChatReader.kt b/domain/src/main/kotlin/gloddy/groupChat/service/GroupChatReader.kt new file mode 100644 index 0000000..49c2c10 --- /dev/null +++ b/domain/src/main/kotlin/gloddy/groupChat/service/GroupChatReader.kt @@ -0,0 +1,27 @@ +package gloddy.groupChat.service + +import gloddy.groupChat.GroupChatMessage +import gloddy.groupChat.dto.command.GroupChatGetMessageCommand +import gloddy.groupChat.repository.GroupChatQueryRepository +import gloddy.util.CursorRequest +import gloddy.util.PageCursor + +class GroupChatReader(private val groupChatQueryRepository: GroupChatQueryRepository) { + + fun getMessages(groupId: Long, cursorRequest: CursorRequest): PageCursor { + var messages = findAllBy(groupId, cursorRequest) + var nextKey = messages.stream() + .mapToLong(GroupChatMessage::sequenceId) + .min() + .orElse(CursorRequest.NONE_KEY) + return PageCursor(cursorRequest.next(nextKey), messages.size, messages) + } + + private fun findAllBy(groupId: Long, cursorRequest: CursorRequest): List { + return if (cursorRequest.hasKey()) { + groupChatQueryRepository.findWithKey(groupId, cursorRequest) + } else { + groupChatQueryRepository.findWithoutKey(groupId) + } + } +} \ No newline at end of file diff --git a/domain/src/main/kotlin/gloddy/port/in/GetGroupChatMessageUseCase.kt b/domain/src/main/kotlin/gloddy/port/in/GetGroupChatMessageUseCase.kt deleted file mode 100644 index 5b44582..0000000 --- a/domain/src/main/kotlin/gloddy/port/in/GetGroupChatMessageUseCase.kt +++ /dev/null @@ -1,10 +0,0 @@ -package gloddy.port.`in` - -import gloddy.groupChat.GroupChatMessage -import gloddy.groupChat.dto.command.GroupChatGetMessageCommand -import gloddy.util.PageCursor - -interface GetGroupChatMessageUseCase { - - fun getPosts(groupChatGetMessageCommand: GroupChatGetMessageCommand): PageCursor -} \ No newline at end of file diff --git a/domain/src/main/kotlin/gloddy/port/out/GetGroupChatMessagePort.kt b/domain/src/main/kotlin/gloddy/port/out/GetGroupChatMessagePort.kt deleted file mode 100644 index 0160307..0000000 --- a/domain/src/main/kotlin/gloddy/port/out/GetGroupChatMessagePort.kt +++ /dev/null @@ -1,10 +0,0 @@ -package gloddy.port.out - -import gloddy.groupChat.GroupChatMessage -import gloddy.groupChat.dto.command.GroupChatGetMessageCommand - -interface GetGroupChatMessagePort { - fun findWithoutKey(groupChatGetMessageCommand: GroupChatGetMessageCommand): List - - fun findWithKey(groupChatGetMessageCommand: GroupChatGetMessageCommand): List -} \ No newline at end of file diff --git a/storage/src/main/kotlin/gloddy/adapter/GroupChatMessageCommandAdapter.kt b/storage/src/main/kotlin/gloddy/adapter/GroupChatMessageCommandAdapter.kt deleted file mode 100644 index 080ae2e..0000000 --- a/storage/src/main/kotlin/gloddy/adapter/GroupChatMessageCommandAdapter.kt +++ /dev/null @@ -1,28 +0,0 @@ -package gloddy.adapter - -import gloddy.groupChat.GroupChatMessage -import gloddy.groupChat.dto.command.GroupChatGetMessageCommand -import gloddy.persistence.repository.GroupChatMessageRepository -import gloddy.port.out.GetGroupChatMessagePort - -class GroupChatMessageCommandAdapter( - private val repository: GroupChatMessageRepository) - : GetGroupChatMessagePort { - - override fun findWithoutKey(command: GroupChatGetMessageCommand): List { - return repository.findAllByMemberIdAndOrderByIdDesc( - command.userId, - command.chatId - ) - } - - override fun findWithKey(command: GroupChatGetMessageCommand): List { - return repository.findAllByLessThanIdMemberIdAndOrderByIdDesc( - command.cursorRequest.key, - command.userId, - command.chatId - ) - } - - -} \ No newline at end of file diff --git a/storage/src/main/kotlin/gloddy/adapter/GroupChatQueryAdapterRepository.kt b/storage/src/main/kotlin/gloddy/adapter/GroupChatQueryAdapterRepository.kt new file mode 100644 index 0000000..c6c1e6c --- /dev/null +++ b/storage/src/main/kotlin/gloddy/adapter/GroupChatQueryAdapterRepository.kt @@ -0,0 +1,31 @@ +package gloddy.adapter + +import gloddy.groupChat.GroupChatMessage +import gloddy.groupChat.dto.command.GroupChatGetMessageCommand +import gloddy.groupChat.repository.GroupChatCommandRepository +import gloddy.groupChat.repository.GroupChatQueryRepository +import gloddy.persistence.repository.GroupChatMessageRepository +import gloddy.util.CursorRequest + +class GroupChatQueryAdapterRepository( + private val groupChatMessageRepository: GroupChatMessageRepository, + private val groupChatCommandRepository: GroupChatCommandRepository) + : GroupChatQueryRepository { + + override fun findWithoutKey(groupId: Long): List { + val groupChat = groupChatCommandRepository.findByGroupId(groupId) + return groupChatMessageRepository.findAllByChatIdAndOrderByIdDesc( + groupChat.id + ) + } + + override fun findWithKey(groupId: Long, cursorRequest: CursorRequest): List { + val groupChat = groupChatCommandRepository.findByGroupId(groupId) + return groupChatMessageRepository.findAllByLessThanIdAndChatIdAndOrderByIdDesc( + cursorRequest.key, + groupChat.id + ) + } + + +} \ No newline at end of file diff --git a/storage/src/main/kotlin/gloddy/persistence/repository/GroupChatMessageRepository.kt b/storage/src/main/kotlin/gloddy/persistence/repository/GroupChatMessageRepository.kt index 8e419cd..300a37f 100644 --- a/storage/src/main/kotlin/gloddy/persistence/repository/GroupChatMessageRepository.kt +++ b/storage/src/main/kotlin/gloddy/persistence/repository/GroupChatMessageRepository.kt @@ -26,10 +26,10 @@ class GroupChatMessageRepository(private val namedParameterJdbcTemplate: NamedPa } } - fun findAllByMemberIdAndOrderByIdDesc(userId: Long, chatId: UUID): List { + fun findAllByChatIdAndOrderByIdDesc(chatId: UUID): List { val sql = """ SELECT * - FROM $TABLE as message + FROM $TABLE AS message INNER JOIN GroupChatUser AS user ON user.chatId = message.chatId WHERE chatId = :chatId and user.createdAt < message.createdAt @@ -41,7 +41,7 @@ class GroupChatMessageRepository(private val namedParameterJdbcTemplate: NamedPa return namedParameterJdbcTemplate.query(sql, params, ROW_MAPPER) } - fun findAllByLessThanIdMemberIdAndOrderByIdDesc(sequenceId: Long?, userId: Long, chatId: UUID): List { + fun findAllByLessThanIdAndChatIdAndOrderByIdDesc(sequenceId: Long?, chatId: UUID): List { val sql = """ SELECT * FROM $TABLE From d8e2e2fad4b64f6549a65a91ead6c7cef5b8db6a Mon Sep 17 00:00:00 2001 From: Park - Jeonghwan <990706leo@gmail.com> Date: Thu, 30 May 2024 13:51:44 +0900 Subject: [PATCH 06/11] =?UTF-8?q?refactor:=20JPA=EB=A1=9C=20=EB=B3=80?= =?UTF-8?q?=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../GroupChatQueryAdapterRepository.kt | 14 ++--- .../GroupChatMessageJpaRepository.kt | 24 +++++++- .../repository/GroupChatMessageRepository.kt | 58 ------------------- 3 files changed, 30 insertions(+), 66 deletions(-) delete mode 100644 storage/src/main/kotlin/gloddy/persistence/repository/GroupChatMessageRepository.kt diff --git a/storage/src/main/kotlin/gloddy/adapter/GroupChatQueryAdapterRepository.kt b/storage/src/main/kotlin/gloddy/adapter/GroupChatQueryAdapterRepository.kt index c6c1e6c..71bd9d9 100644 --- a/storage/src/main/kotlin/gloddy/adapter/GroupChatQueryAdapterRepository.kt +++ b/storage/src/main/kotlin/gloddy/adapter/GroupChatQueryAdapterRepository.kt @@ -1,30 +1,30 @@ package gloddy.adapter import gloddy.groupChat.GroupChatMessage -import gloddy.groupChat.dto.command.GroupChatGetMessageCommand import gloddy.groupChat.repository.GroupChatCommandRepository import gloddy.groupChat.repository.GroupChatQueryRepository -import gloddy.persistence.repository.GroupChatMessageRepository +import gloddy.persistence.repository.GroupChatMessageJpaRepository +import gloddy.persistence.util.toDomain import gloddy.util.CursorRequest class GroupChatQueryAdapterRepository( - private val groupChatMessageRepository: GroupChatMessageRepository, + private val groupChatMessageJpaRepository: GroupChatMessageJpaRepository, private val groupChatCommandRepository: GroupChatCommandRepository) : GroupChatQueryRepository { override fun findWithoutKey(groupId: Long): List { val groupChat = groupChatCommandRepository.findByGroupId(groupId) - return groupChatMessageRepository.findAllByChatIdAndOrderByIdDesc( + return groupChatMessageJpaRepository.findAllByChatIdAndOrderByIdDesc( groupChat.id - ) + ).map { it.toDomain() } } override fun findWithKey(groupId: Long, cursorRequest: CursorRequest): List { val groupChat = groupChatCommandRepository.findByGroupId(groupId) - return groupChatMessageRepository.findAllByLessThanIdAndChatIdAndOrderByIdDesc( + return groupChatMessageJpaRepository.findAllByLessThanIdAndChatIdAndOrderByIdDesc( cursorRequest.key, groupChat.id - ) + ).map { it.toDomain() } } diff --git a/storage/src/main/kotlin/gloddy/persistence/repository/GroupChatMessageJpaRepository.kt b/storage/src/main/kotlin/gloddy/persistence/repository/GroupChatMessageJpaRepository.kt index 415279d..eb3896b 100644 --- a/storage/src/main/kotlin/gloddy/persistence/repository/GroupChatMessageJpaRepository.kt +++ b/storage/src/main/kotlin/gloddy/persistence/repository/GroupChatMessageJpaRepository.kt @@ -1,10 +1,32 @@ package gloddy.persistence.repository +import gloddy.groupChat.GroupChatMessage import gloddy.persistence.GroupChatMessageEntity import org.springframework.data.jpa.repository.JpaRepository -import java.util.UUID +import org.springframework.data.jpa.repository.Query +import java.util.* interface GroupChatMessageJpaRepository : JpaRepository { fun findById(id: UUID): GroupChatMessageEntity? fun findFirstByOrderBySequenceIdDesc(): GroupChatMessageEntity + + @Query( + value = "SELECT * " + + "FROM GROUPCHATMESSAGE AS message " + + "INNER JOIN GroupChatUser AS user " + + " ON user.chatId = message.chatId " + + "WHERE chatId = :chatId and user.createdAt < message.createdAt " + + "ORDER BY sequenceId desc ", + nativeQuery = true + ) + fun findAllByChatIdAndOrderByIdDesc(chatId: UUID): List + + @Query( + value = "SELECT * " + + "FROM GROUPCHATMESSAGE " + + "WHERE chatId = :chatId and sequenceId < :sequenceId " + + "ORDER BY sequenceId desc ", + nativeQuery = true + ) + fun findAllByLessThanIdAndChatIdAndOrderByIdDesc(sequenceId: Long?, chatId: UUID): List } \ No newline at end of file diff --git a/storage/src/main/kotlin/gloddy/persistence/repository/GroupChatMessageRepository.kt b/storage/src/main/kotlin/gloddy/persistence/repository/GroupChatMessageRepository.kt deleted file mode 100644 index 300a37f..0000000 --- a/storage/src/main/kotlin/gloddy/persistence/repository/GroupChatMessageRepository.kt +++ /dev/null @@ -1,58 +0,0 @@ -package gloddy.persistence.repository - -import gloddy.groupChat.GroupChatMessage -import gloddy.groupChat.vo.MessageType -import org.springframework.jdbc.core.RowMapper -import org.springframework.jdbc.core.namedparam.MapSqlParameterSource -import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate -import java.time.LocalDateTime -import java.util.* - -class GroupChatMessageRepository(private val namedParameterJdbcTemplate: NamedParameterJdbcTemplate) { - - companion object { - private const val TABLE = "GroupChatMessage" - private val ROW_MAPPER: RowMapper = RowMapper { rs, rowNum -> - GroupChatMessage( - userId = rs.getLong("userId"), - chatId = rs.getObject("chatId", UUID::class.java), - messageType = MessageType.valueOf(rs.getString("messageType")), - content = rs.getString("content"), - createdAt = rs.getObject("createdAt", LocalDateTime::class.java) ?: LocalDateTime.now(), - deleted = rs.getBoolean("deleted"), - deletedAt = rs.getObject("deletedAt", LocalDateTime::class.java), - id = rs.getObject("id", UUID::class.java), - sequenceId = rs.getLong("sequenceId")) - } - } - - fun findAllByChatIdAndOrderByIdDesc(chatId: UUID): List { - val sql = """ - SELECT * - FROM $TABLE AS message - INNER JOIN GroupChatUser AS user - ON user.chatId = message.chatId - WHERE chatId = :chatId and user.createdAt < message.createdAt - ORDER BY sequenceId desc - """.trimIndent() - val params = MapSqlParameterSource() - .addValue("chatId", chatId) - - return namedParameterJdbcTemplate.query(sql, params, ROW_MAPPER) - } - - fun findAllByLessThanIdAndChatIdAndOrderByIdDesc(sequenceId: Long?, chatId: UUID): List { - val sql = """ - SELECT * - FROM $TABLE - WHERE chatId = :chatId and sequenceId < :sequenceId - ORDER BY sequenceId desc - """.trimIndent() - val params = MapSqlParameterSource() - .addValue("sequenceId", sequenceId) - .addValue("chatId", chatId) - - return namedParameterJdbcTemplate.query(sql, params, ROW_MAPPER) - } - -} \ No newline at end of file From 5fdd6eec002596f3d6615171bff6dfcb26b1ccd2 Mon Sep 17 00:00:00 2001 From: Park - Jeonghwan <990706leo@gmail.com> Date: Thu, 30 May 2024 22:40:34 +0900 Subject: [PATCH 07/11] =?UTF-8?q?fix:=20=ED=8C=A8=ED=82=A4=EC=A7=80=20?= =?UTF-8?q?=EA=B5=AC=EC=A1=B0=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- api/src/main/kotlin/gloddy/GloddyChatApplication.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/api/src/main/kotlin/gloddy/GloddyChatApplication.kt b/api/src/main/kotlin/gloddy/GloddyChatApplication.kt index 44e53cd..1c1f33d 100644 --- a/api/src/main/kotlin/gloddy/GloddyChatApplication.kt +++ b/api/src/main/kotlin/gloddy/GloddyChatApplication.kt @@ -1,4 +1,4 @@ -package gloddy.api +package gloddy import org.springframework.boot.autoconfigure.SpringBootApplication import org.springframework.boot.runApplication From 9979e44af15e637ea0006fa550e1ab3eec7035b5 Mon Sep 17 00:00:00 2001 From: Park - Jeonghwan <990706leo@gmail.com> Date: Thu, 30 May 2024 22:41:05 +0900 Subject: [PATCH 08/11] =?UTF-8?q?refactor:=20=EB=A6=AC=EB=B7=B0=20?= =?UTF-8?q?=EB=B0=98=EC=98=81=20=EB=B0=8F=20=ED=85=8C=EC=8A=A4=ED=8A=B8=20?= =?UTF-8?q?=EC=99=84=EB=A3=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/GroupChatQueryController.kt | 24 ++++++++------ .../repository/GroupChatQueryRepository.kt | 5 +-- .../groupChat/service/GroupChatReader.kt | 18 ++++++----- .../GroupChatQueryAdapterRepository.kt | 31 +++++++++++++------ .../GroupChatMessageJpaRepository.kt | 28 ++++++++--------- .../repository/GroupChatUserJpaRepository.kt | 3 +- 6 files changed, 64 insertions(+), 45 deletions(-) diff --git a/api/src/main/kotlin/gloddy/controller/GroupChatQueryController.kt b/api/src/main/kotlin/gloddy/controller/GroupChatQueryController.kt index 87a8859..ad6c127 100644 --- a/api/src/main/kotlin/gloddy/controller/GroupChatQueryController.kt +++ b/api/src/main/kotlin/gloddy/controller/GroupChatQueryController.kt @@ -1,21 +1,25 @@ package gloddy.controller import gloddy.groupChat.GroupChatMessage -import gloddy.groupChat.dto.command.GroupChatGetMessageCommand +import gloddy.groupChat.service.GroupChatCommander import gloddy.groupChat.service.GroupChatReader import gloddy.util.CursorRequest import gloddy.util.PageCursor -import org.springframework.web.bind.annotation.GetMapping -import org.springframework.web.bind.annotation.PathVariable -import org.springframework.web.bind.annotation.RequestBody +import org.springframework.web.bind.annotation.* -class GroupChatQueryController(private val groupChatReader: GroupChatReader) { +@RestController +class GroupChatQueryController( + private val groupChatReader: GroupChatReader, + private val groupChatCommander: GroupChatCommander +) { - @GetMapping("group-chat/{groupId}/messages") - fun getGroupChatMessages(@PathVariable("groupId") groupId:Long, - @RequestBody cursorRequest: CursorRequest) - : PageCursor{ + @GetMapping("/group-chat-messages/{groupId}") + fun getGroupChatMessagesByCursor( + @PathVariable("groupId") groupId: Long, + userId: Long, + @RequestBody(required = false) cursorRequest: CursorRequest + ): PageCursor { - return groupChatReader.getMessages(groupId, cursorRequest) + return groupChatReader.getMessagesByCursor(groupId, userId, cursorRequest) } } \ No newline at end of file diff --git a/domain/src/main/kotlin/gloddy/groupChat/repository/GroupChatQueryRepository.kt b/domain/src/main/kotlin/gloddy/groupChat/repository/GroupChatQueryRepository.kt index 1abab03..f39256f 100644 --- a/domain/src/main/kotlin/gloddy/groupChat/repository/GroupChatQueryRepository.kt +++ b/domain/src/main/kotlin/gloddy/groupChat/repository/GroupChatQueryRepository.kt @@ -1,11 +1,12 @@ package gloddy.groupChat.repository import gloddy.groupChat.GroupChatMessage -import gloddy.groupChat.dto.command.GroupChatGetMessageCommand import gloddy.util.CursorRequest +import java.time.LocalDateTime interface GroupChatQueryRepository { - fun findWithoutKey(groupId: Long): List + fun findWithoutKey(groupId: Long, createdAt: LocalDateTime): List fun findWithKey(groupId: Long, cursorRequest: CursorRequest): List + fun findUserCreatedAtById(userId: Long): LocalDateTime } \ No newline at end of file diff --git a/domain/src/main/kotlin/gloddy/groupChat/service/GroupChatReader.kt b/domain/src/main/kotlin/gloddy/groupChat/service/GroupChatReader.kt index 49c2c10..4be7171 100644 --- a/domain/src/main/kotlin/gloddy/groupChat/service/GroupChatReader.kt +++ b/domain/src/main/kotlin/gloddy/groupChat/service/GroupChatReader.kt @@ -1,27 +1,29 @@ package gloddy.groupChat.service import gloddy.groupChat.GroupChatMessage -import gloddy.groupChat.dto.command.GroupChatGetMessageCommand import gloddy.groupChat.repository.GroupChatQueryRepository import gloddy.util.CursorRequest import gloddy.util.PageCursor +import org.springframework.stereotype.Service +@Service class GroupChatReader(private val groupChatQueryRepository: GroupChatQueryRepository) { - fun getMessages(groupId: Long, cursorRequest: CursorRequest): PageCursor { - var messages = findAllBy(groupId, cursorRequest) + fun getMessagesByCursor(groupId: Long, userId: Long, cursorRequest: CursorRequest): PageCursor { + var messages = findAll(groupId, userId, cursorRequest) var nextKey = messages.stream() - .mapToLong(GroupChatMessage::sequenceId) - .min() - .orElse(CursorRequest.NONE_KEY) + .mapToLong(GroupChatMessage::sequenceId) + .min() + .orElse(CursorRequest.NONE_KEY) return PageCursor(cursorRequest.next(nextKey), messages.size, messages) } - private fun findAllBy(groupId: Long, cursorRequest: CursorRequest): List { + private fun findAll(groupId: Long, userId: Long, cursorRequest: CursorRequest): List { return if (cursorRequest.hasKey()) { groupChatQueryRepository.findWithKey(groupId, cursorRequest) } else { - groupChatQueryRepository.findWithoutKey(groupId) + val createdAt = groupChatQueryRepository.findUserCreatedAtById(userId) + groupChatQueryRepository.findWithoutKey(groupId, createdAt) } } } \ No newline at end of file diff --git a/storage/src/main/kotlin/gloddy/adapter/GroupChatQueryAdapterRepository.kt b/storage/src/main/kotlin/gloddy/adapter/GroupChatQueryAdapterRepository.kt index 71bd9d9..d3ad60c 100644 --- a/storage/src/main/kotlin/gloddy/adapter/GroupChatQueryAdapterRepository.kt +++ b/storage/src/main/kotlin/gloddy/adapter/GroupChatQueryAdapterRepository.kt @@ -1,31 +1,42 @@ package gloddy.adapter import gloddy.groupChat.GroupChatMessage -import gloddy.groupChat.repository.GroupChatCommandRepository +import gloddy.groupChat.GroupChatUserNotFoundException import gloddy.groupChat.repository.GroupChatQueryRepository import gloddy.persistence.repository.GroupChatMessageJpaRepository +import gloddy.persistence.repository.GroupChatUserJpaRepository import gloddy.persistence.util.toDomain import gloddy.util.CursorRequest +import org.springframework.stereotype.Component +import java.time.LocalDateTime +@Component class GroupChatQueryAdapterRepository( - private val groupChatMessageJpaRepository: GroupChatMessageJpaRepository, - private val groupChatCommandRepository: GroupChatCommandRepository) - : GroupChatQueryRepository { + private val groupChatMessageJpaRepository: GroupChatMessageJpaRepository, + private val groupChatUserJpaRepository: GroupChatUserJpaRepository, + private val groupChatCommandAdapterRepository: GroupChatCommandAdapterRepository +) : GroupChatQueryRepository { - override fun findWithoutKey(groupId: Long): List { - val groupChat = groupChatCommandRepository.findByGroupId(groupId) + override fun findWithoutKey(groupId: Long, createdAt: LocalDateTime): List { + val groupChat = groupChatCommandAdapterRepository.findByGroupId(groupId) return groupChatMessageJpaRepository.findAllByChatIdAndOrderByIdDesc( - groupChat.id + createdAt, + groupChat.id ).map { it.toDomain() } } override fun findWithKey(groupId: Long, cursorRequest: CursorRequest): List { - val groupChat = groupChatCommandRepository.findByGroupId(groupId) + val groupChat = groupChatCommandAdapterRepository.findByGroupId(groupId) return groupChatMessageJpaRepository.findAllByLessThanIdAndChatIdAndOrderByIdDesc( - cursorRequest.key, - groupChat.id + cursorRequest.key, + groupChat.id ).map { it.toDomain() } } + override fun findUserCreatedAtById(userId: Long): LocalDateTime { + val found = groupChatUserJpaRepository.findByUserId(userId) + return found?.createdAt ?: throw GroupChatUserNotFoundException() + } + } \ No newline at end of file diff --git a/storage/src/main/kotlin/gloddy/persistence/repository/GroupChatMessageJpaRepository.kt b/storage/src/main/kotlin/gloddy/persistence/repository/GroupChatMessageJpaRepository.kt index eb3896b..1b28c89 100644 --- a/storage/src/main/kotlin/gloddy/persistence/repository/GroupChatMessageJpaRepository.kt +++ b/storage/src/main/kotlin/gloddy/persistence/repository/GroupChatMessageJpaRepository.kt @@ -1,9 +1,9 @@ package gloddy.persistence.repository -import gloddy.groupChat.GroupChatMessage import gloddy.persistence.GroupChatMessageEntity import org.springframework.data.jpa.repository.JpaRepository import org.springframework.data.jpa.repository.Query +import java.time.LocalDateTime import java.util.* interface GroupChatMessageJpaRepository : JpaRepository { @@ -11,22 +11,22 @@ interface GroupChatMessageJpaRepository : JpaRepository + fun findAllByChatIdAndOrderByIdDesc(createdAt: LocalDateTime, chatId: UUID): List @Query( - value = "SELECT * " + - "FROM GROUPCHATMESSAGE " + - "WHERE chatId = :chatId and sequenceId < :sequenceId " + - "ORDER BY sequenceId desc ", - nativeQuery = true + value = "SELECT * " + + "FROM group_chat_message m " + + "WHERE chat_id = :chatId and sequence_id < :sequenceId and not m.type in ('SYSTEM_JOIN') " + + "ORDER BY sequence_id desc", + nativeQuery = true ) fun findAllByLessThanIdAndChatIdAndOrderByIdDesc(sequenceId: Long?, chatId: UUID): List } \ No newline at end of file diff --git a/storage/src/main/kotlin/gloddy/persistence/repository/GroupChatUserJpaRepository.kt b/storage/src/main/kotlin/gloddy/persistence/repository/GroupChatUserJpaRepository.kt index 5ce56d4..b3a529c 100644 --- a/storage/src/main/kotlin/gloddy/persistence/repository/GroupChatUserJpaRepository.kt +++ b/storage/src/main/kotlin/gloddy/persistence/repository/GroupChatUserJpaRepository.kt @@ -2,9 +2,10 @@ package gloddy.persistence.repository import gloddy.persistence.GroupChatUserEntity import org.springframework.data.jpa.repository.JpaRepository -import java.util.UUID +import java.util.* interface GroupChatUserJpaRepository : JpaRepository { fun findById(id: UUID): GroupChatUserEntity? fun findFirstByOrderBySequenceIdDesc(): GroupChatUserEntity + fun findByUserId(userId: Long): GroupChatUserEntity? } \ No newline at end of file From 6231163a0bc742a3c8462f4d5f37231ec1cca373 Mon Sep 17 00:00:00 2001 From: Park - Jeonghwan <990706leo@gmail.com> Date: Thu, 30 May 2024 22:41:28 +0900 Subject: [PATCH 09/11] =?UTF-8?q?feat:=20=EC=98=88=EC=99=B8=EC=B2=98?= =?UTF-8?q?=EB=A6=AC=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- domain/src/main/kotlin/gloddy/core/ErrorCode.kt | 4 ++++ .../src/main/kotlin/gloddy/groupChat/GroupChatException.kt | 6 ++++++ 2 files changed, 10 insertions(+) diff --git a/domain/src/main/kotlin/gloddy/core/ErrorCode.kt b/domain/src/main/kotlin/gloddy/core/ErrorCode.kt index c4aebe4..850b765 100644 --- a/domain/src/main/kotlin/gloddy/core/ErrorCode.kt +++ b/domain/src/main/kotlin/gloddy/core/ErrorCode.kt @@ -11,4 +11,8 @@ enum class ErrorCode( //GroupChatMessage GROUP_CHAT_MESSAGE_NOT_FOUND(404, "GROUP_CHAT_003", "그룹 채팅 메시지를 찾을 수 없습니다."), + + //GroupChatUser + GROUP_CHAT_USER_NOT_FOUND(404, "GROUP_CHAT_USER_005", "유저를 찾을 수 없습니다.") + } \ No newline at end of file diff --git a/domain/src/main/kotlin/gloddy/groupChat/GroupChatException.kt b/domain/src/main/kotlin/gloddy/groupChat/GroupChatException.kt index f59d433..f2242f3 100644 --- a/domain/src/main/kotlin/gloddy/groupChat/GroupChatException.kt +++ b/domain/src/main/kotlin/gloddy/groupChat/GroupChatException.kt @@ -19,4 +19,10 @@ class GroupChatMessageNotFoundException : GloddyChatException( statusCode = ErrorCode.GROUP_CHAT_MESSAGE_NOT_FOUND.statusCode, errorCode = ErrorCode.GROUP_CHAT_MESSAGE_NOT_FOUND.errorCode, message = ErrorCode.GROUP_CHAT_MESSAGE_NOT_FOUND.message +) + +class GroupChatUserNotFoundException : GloddyChatException( + statusCode = ErrorCode.GROUP_CHAT_USER_NOT_FOUND.statusCode, + errorCode = ErrorCode.GROUP_CHAT_USER_NOT_FOUND.errorCode, + message = ErrorCode.GROUP_CHAT_USER_NOT_FOUND.message ) \ No newline at end of file From 8ed4d1b5ee642abfd60c7adebe6e5cf5b6945b5f Mon Sep 17 00:00:00 2001 From: Park - Jeonghwan <990706leo@gmail.com> Date: Thu, 30 May 2024 13:52:50 +0900 Subject: [PATCH 10/11] =?UTF-8?q?fix:=20=EC=98=A4=ED=83=80=20=EC=88=98?= =?UTF-8?q?=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- api/src/main/resources/application.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/api/src/main/resources/application.yml b/api/src/main/resources/application.yml index 7526746..f561f9f 100644 --- a/api/src/main/resources/application.yml +++ b/api/src/main/resources/application.yml @@ -8,4 +8,4 @@ spring: - application-client.yml - application-aws-credentials.yml - application-in-message.yml - - application-out-message + - application-out-message.yml From 76e58a31432be9892c9e27dd7c3123b434cf8066 Mon Sep 17 00:00:00 2001 From: Park - Jeonghwan <990706leo@gmail.com> Date: Thu, 30 May 2024 13:53:11 +0900 Subject: [PATCH 11/11] =?UTF-8?q?fix:=20storage=20=EC=9D=98=EC=A1=B4?= =?UTF-8?q?=EC=84=B1=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- api/build.gradle.kts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/api/build.gradle.kts b/api/build.gradle.kts index 2ebb10e..b531795 100644 --- a/api/build.gradle.kts +++ b/api/build.gradle.kts @@ -5,7 +5,7 @@ dependencies { implementation(project(":client")) implementation(project(":in-message")) implementation(project(":out-message")) - implementation(project(":client")) + implementation(project(":storage")) implementation("org.springframework.boot:spring-boot-starter-web") implementation("org.springframework.boot:spring-boot-starter-websocket") }