This repository has been archived by the owner on May 19, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
80a157d
commit 35298a2
Showing
9 changed files
with
189 additions
and
0 deletions.
There are no files selected for viewing
30 changes: 30 additions & 0 deletions
30
...n/src/main/kotlin/com/studentcenter/weave/application/chat/port/inbound/GetChatMessage.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package com.studentcenter.weave.application.chat.port.inbound | ||
|
||
import com.studentcenter.weave.domain.chat.entity.ChatMessage | ||
import com.studentcenter.weave.support.common.dto.ScrollRequest | ||
import com.studentcenter.weave.support.common.dto.ScrollResponse | ||
import java.util.UUID | ||
|
||
interface GetChatMessage { | ||
|
||
fun getScrollList(query: ScrollListQuery): ScrollListResult | ||
|
||
data class ScrollListQuery( | ||
val chatRoomId: UUID, | ||
override val next: UUID?, | ||
override val limit: Int | ||
) : ScrollRequest<UUID?>( | ||
next = next, | ||
limit = limit | ||
) | ||
|
||
data class ScrollListResult( | ||
override val items: List<ChatMessage>, | ||
override val next: UUID?, | ||
) : ScrollResponse<ChatMessage, UUID?>( | ||
items = items, | ||
next = next, | ||
total = items.size, | ||
) | ||
|
||
} |
3 changes: 3 additions & 0 deletions
3
...in/kotlin/com/studentcenter/weave/application/chat/port/outbound/ChatMessageRepository.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,12 @@ | ||
package com.studentcenter.weave.application.chat.port.outbound | ||
|
||
import com.studentcenter.weave.application.chat.port.inbound.GetChatMessage | ||
import com.studentcenter.weave.domain.chat.entity.ChatMessage | ||
|
||
interface ChatMessageRepository { | ||
|
||
fun save(chatMessage: ChatMessage) | ||
|
||
fun getScrollList(query: GetChatMessage.ScrollListQuery): List<ChatMessage> | ||
|
||
} |
26 changes: 26 additions & 0 deletions
26
...src/main/kotlin/com/studentcenter/weave/application/chat/service/GetChatMessageService.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package com.studentcenter.weave.application.chat.service | ||
|
||
import com.studentcenter.weave.application.chat.port.inbound.GetChatMessage | ||
import com.studentcenter.weave.application.chat.port.outbound.ChatMessageRepository | ||
import com.studentcenter.weave.domain.chat.entity.ChatMessage | ||
import org.springframework.stereotype.Service | ||
import org.springframework.transaction.annotation.Transactional | ||
|
||
@Service | ||
@Transactional(readOnly = true) | ||
class GetChatMessageService( | ||
private val chatMessageRepository: ChatMessageRepository, | ||
) : GetChatMessage { | ||
|
||
override fun getScrollList(query: GetChatMessage.ScrollListQuery): GetChatMessage.ScrollListResult { | ||
val result: List<ChatMessage> = query | ||
.copy(limit = query.limit + 1) | ||
.let { chatMessageRepository.getScrollList(it) } | ||
|
||
return GetChatMessage.ScrollListResult( | ||
items = result.take(query.limit), | ||
next = if (result.size > query.limit) result.last().id else null | ||
) | ||
} | ||
|
||
} |
23 changes: 23 additions & 0 deletions
23
bootstrap/http/src/main/kotlin/com/studentcenter/weave/bootstrap/chat/api/ChatMessageApi.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package com.studentcenter.weave.bootstrap.chat.api | ||
|
||
import com.studentcenter.weave.bootstrap.chat.dto.GetChatMessagesRequest | ||
import com.studentcenter.weave.bootstrap.chat.dto.GetChatMessagesResponse | ||
import com.studentcenter.weave.bootstrap.common.security.annotation.Secured | ||
import io.swagger.v3.oas.annotations.Operation | ||
import io.swagger.v3.oas.annotations.tags.Tag | ||
import org.springframework.http.HttpStatus | ||
import org.springframework.web.bind.annotation.GetMapping | ||
import org.springframework.web.bind.annotation.RequestMapping | ||
import org.springframework.web.bind.annotation.ResponseStatus | ||
|
||
@Tag(name = "ChatMessage", description = "채팅 메시지 API") | ||
@RequestMapping("/api/chat-messages") | ||
interface ChatMessageApi { | ||
|
||
@Secured | ||
@Operation(summary = "채팅 메시지 조회") | ||
@GetMapping | ||
@ResponseStatus(HttpStatus.OK) | ||
fun getChatMessages(request: GetChatMessagesRequest): GetChatMessagesResponse | ||
|
||
} |
23 changes: 23 additions & 0 deletions
23
...ain/kotlin/com/studentcenter/weave/bootstrap/chat/controller/ChatMessageRestController.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package com.studentcenter.weave.bootstrap.chat.controller | ||
|
||
import com.studentcenter.weave.application.chat.port.inbound.GetChatMessage | ||
import com.studentcenter.weave.bootstrap.chat.api.ChatMessageApi | ||
import com.studentcenter.weave.bootstrap.chat.dto.GetChatMessagesRequest | ||
import com.studentcenter.weave.bootstrap.chat.dto.GetChatMessagesResponse | ||
import com.studentcenter.weave.bootstrap.chat.dto.GetChatMessagesResponse.Companion.toResponse | ||
import org.springframework.web.bind.annotation.RestController | ||
|
||
@RestController | ||
class ChatMessageRestController( | ||
private val getChatMessage: GetChatMessage, | ||
) : ChatMessageApi { | ||
|
||
override fun getChatMessages(request: GetChatMessagesRequest): GetChatMessagesResponse { | ||
val (chatRoomId, next, limit) = request.validate() | ||
return GetChatMessage | ||
.ScrollListQuery(chatRoomId, next, limit) | ||
.let { getChatMessage.getScrollList(it) } | ||
.toResponse() | ||
} | ||
|
||
} |
29 changes: 29 additions & 0 deletions
29
...http/src/main/kotlin/com/studentcenter/weave/bootstrap/chat/dto/GetChatMessagesRequest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package com.studentcenter.weave.bootstrap.chat.dto | ||
|
||
import io.swagger.v3.oas.annotations.media.Schema | ||
import java.util.* | ||
|
||
@Schema(description = "채팅 메시지 조회 요청") | ||
data class GetChatMessagesRequest( | ||
@Schema(description = "채팅방 ID", example = "123e4567-e89b-12d3-a456-426614174000") | ||
val chatRoomId: UUID?, | ||
@Schema(description = "이전 메시지 조회를 위한 cursor", example = "123e4567-e89b-12d3-a456-426614174000") | ||
val next: UUID?, | ||
@Schema(description = "한번에 조회할 메시지 수", defaultValue = "20", example = "20") | ||
val limit: Int? = 20, | ||
) { | ||
|
||
fun validate(): Validated { | ||
requireNotNull(chatRoomId) { "유효하지 않은 채팅방 입니다" } | ||
requireNotNull(limit) { "유효하지 않은 요청입니다"} | ||
require(limit > 0) { "한번에 조회할 메시지 수는 0보다 커야 합니다" } | ||
return Validated(chatRoomId, next, limit) | ||
} | ||
|
||
data class Validated( | ||
val chatRoomId: UUID, | ||
val next: UUID?, | ||
val limit: Int, | ||
) | ||
|
||
} |
26 changes: 26 additions & 0 deletions
26
...ttp/src/main/kotlin/com/studentcenter/weave/bootstrap/chat/dto/GetChatMessagesResponse.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package com.studentcenter.weave.bootstrap.chat.dto | ||
|
||
import com.studentcenter.weave.application.chat.port.inbound.GetChatMessage | ||
import com.studentcenter.weave.domain.chat.entity.ChatMessage | ||
import io.swagger.v3.oas.annotations.media.Schema | ||
import java.util.* | ||
|
||
@Schema(description = "채팅 메시지 목록 조회 응답") | ||
data class GetChatMessagesResponse( | ||
@Schema(description = "채팅 메시지 목록") | ||
val items: List<ChatMessage>, | ||
@Schema(description = "다음 메시지 ID") | ||
val next: UUID?, | ||
@Schema(description = "조회한 메시지 수") | ||
val total: Int, | ||
) { | ||
companion object { | ||
fun GetChatMessage.ScrollListResult.toResponse(): GetChatMessagesResponse { | ||
return GetChatMessagesResponse( | ||
items = this.items, | ||
next = this.next, | ||
total = this.total, | ||
) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters