Skip to content

Commit

Permalink
feat(chat): 메시지 이벤트 객체 구조 개선
Browse files Browse the repository at this point in the history
  • Loading branch information
waterfogSW committed Jan 13, 2025
1 parent 61a4389 commit 70d00a5
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,29 +9,36 @@ data class ReceiveMessageWebSocketEvent(
val id: UUID,
val channelId: UUID,
val senderUserId: UUID,
val contentType: String,
val contentText: String,
val contentCardColor: String?,
val content: Content,
val createdAt: LocalDateTime,
) {

data class Content(
val type: String,
val text: String,
val cardColor: String?,
)

companion object {

fun ReceiveMessageEvent.toWebSocketEvent(): ReceiveMessageWebSocketEvent {
return ReceiveMessageWebSocketEvent(
id = id.value,
channelId = channelId.value,
senderUserId = senderUserId.value,
contentType = content::class.simpleName!!,
contentText = when (content) {
is Message.Content.Text -> (content as Message.Content.Text).text
is Message.Content.Card -> (content as Message.Content.Card).text
},
contentCardColor = when (content) {
is Message.Content.Card -> (content as Message.Content.Card).color.name
else -> null
},
content = Content(
type = content::class.simpleName!!,
text = when (content) {
is Message.Content.Text -> (content as Message.Content.Text).text
is Message.Content.Card -> (content as Message.Content.Card).text
},
cardColor = when (content) {
is Message.Content.Card -> (content as Message.Content.Card).color.name
else -> null
}
),
createdAt = createdAt,
)
}
}

}
41 changes: 37 additions & 4 deletions bootstrap/api/src/main/resources/static/websocket-test.html
Original file line number Diff line number Diff line change
Expand Up @@ -310,11 +310,44 @@ <h3>2. 채널 구독</h3>
"id": "UUID", // 메시지 고유 ID
"channelId": "UUID", // 채널 ID
"senderUserId": "UUID", // 발신자 ID
"contentType": "TEXT" | "CARD", // 메시지 타입
"contentText": "string", // 메시지 내용
"contentCardColor": "BLUE" | "PINK" | null, // CARD 타입일 경우 색상
"createdAt": "2025-01-13T00:39:24" // ISO-8601 형식
"content": { // 메시지 내용
"type": "TEXT" | "CARD", // 메시지 타입
"text": "string", // 메시지 텍스트
"cardColor": "BLUE" | "PINK" | null // CARD 타입일 경우 색상
},
"createdAt": "2025-01-13T22:25:56" // ISO-8601 형식
}

// 예시 - TEXT 타입
{
"id": "550e8400-e29b-41d4-a716-446655440000",
"channelId": "33333333-3333-3333-3333-333333333333",
"senderUserId": "44444444-4444-4444-4444-444444444444",
"content": {
"type": "TEXT",
"text": "안녕하세요",
"cardColor": null
},
"createdAt": "2025-01-13T22:25:56"
}

// 예시 - CARD 타입
{
"id": "550e8400-e29b-41d4-a716-446655440000",
"channelId": "33333333-3333-3333-3333-333333333333",
"senderUserId": "44444444-4444-4444-4444-444444444444",
"content": {
"type": "CARD",
"text": "카드 메시지입니다",
"cardColor": "BLUE"
},
"createdAt": "2025-01-13T22:25:56"
}</pre>
<br>
<p><strong>수신 메시지 상태 코드</strong></p>
- 200: 메시지 수신 성공<br>
- 401: 인증 실패<br>
- 404: 채널 없음<br>
</div>
<div class="input-group">
<input type="text" id="subscription" value="/channel/33333333-3333-3333-3333-333333333333"
Expand Down

0 comments on commit 70d00a5

Please sign in to comment.