Skip to content

Commit

Permalink
refactor(chat) : ID 생성 UUID v8 사용하도록 변경
Browse files Browse the repository at this point in the history
  • Loading branch information
waterfogSW committed Feb 2, 2025
1 parent d5f16e7 commit c0df2aa
Showing 1 changed file with 6 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package com.threedays.domain.chat.entity
import com.threedays.domain.user.entity.User
import com.threedays.domain.user.vo.Gender
import com.threedays.support.common.base.domain.AggregateRoot
import com.threedays.support.common.base.domain.TypeId
import com.threedays.support.common.base.domain.UUIDTypeId
import java.time.LocalDateTime
import java.util.*

Expand All @@ -17,7 +17,7 @@ data class Message(
val updatedAt: LocalDateTime? = null,
) : AggregateRoot<Message, Message.Id>() {

data class Id(override val value: UUID) : TypeId<UUID>(value)
data class Id(override val value: UUID) : UUIDTypeId(value)

sealed class Content {
data class Text(val text: String) : Content()
Expand All @@ -38,18 +38,19 @@ data class Message(
}

companion object {

fun createCardMessage(
channelId: Channel.Id,
sender: User,
text: String,
): Message {
val color: Content.Card.Color = when(sender.profile.gender) {
val color: Content.Card.Color = when (sender.profile.gender) {
Gender.MALE -> Content.Card.Color.BLUE
Gender.FEMALE -> Content.Card.Color.PINK
}

return Message(
id = Id(UUID.randomUUID()),
id = UUIDTypeId.random(),
channelId = channelId,
senderUserId = sender.id,
content = Content.Card(text, color)
Expand All @@ -62,7 +63,7 @@ data class Message(
text: String
): Message {
return Message(
id = Id(UUID.randomUUID()),
id = UUIDTypeId.random(),
channelId = channelId,
senderUserId = sender.id,
content = Content.Text(text)
Expand Down

0 comments on commit c0df2aa

Please sign in to comment.