diff --git a/domain/src/main/kotlin/com/threedays/domain/chat/entity/ChatMember.kt b/domain/src/main/kotlin/com/threedays/domain/chat/entity/ChatMember.kt new file mode 100644 index 0000000..74cebd5 --- /dev/null +++ b/domain/src/main/kotlin/com/threedays/domain/chat/entity/ChatMember.kt @@ -0,0 +1,17 @@ +package com.threedays.domain.chat.entity + +import com.threedays.domain.user.entity.User +import com.threedays.support.common.base.domain.DomainEntity +import com.threedays.support.common.base.domain.TypeId +import java.time.LocalDateTime +import java.util.* + +data class ChatMember( + override val id: Id, + val userId: User.Id, + val joinedAt: LocalDateTime = LocalDateTime.now() +) : DomainEntity() { + + data class Id(override val value: UUID) : TypeId(value) + +} diff --git a/domain/src/main/kotlin/com/threedays/domain/chat/entity/ChatMessage.kt b/domain/src/main/kotlin/com/threedays/domain/chat/entity/ChatMessage.kt new file mode 100644 index 0000000..9637ce1 --- /dev/null +++ b/domain/src/main/kotlin/com/threedays/domain/chat/entity/ChatMessage.kt @@ -0,0 +1,53 @@ +package com.threedays.domain.chat.entity + +import com.threedays.support.common.base.domain.AggregateRoot +import com.threedays.support.common.base.domain.TypeId +import java.time.LocalDateTime +import java.util.* + +data class ChatMessage( + override val id: Id, + val chatRoomId: ChatRoom.Id, + val senderId: ChatMember.Id, + val content: String, + val status: Status = Status.SENT, + val createdAt: LocalDateTime = LocalDateTime.now(), + val updatedAt: LocalDateTime? = null, + val failureReason: FailureReason? = null +) : AggregateRoot() { + + data class Id(override val value: UUID) : TypeId(value) + + + enum class Status { + SENT, + READ, + FAILED, + } + + enum class FailureReason { + NETWORK_ERROR, + INVALID_RECIPIENT, + MESSAGE_TOO_LARGE, + UNKNOWN_ERROR + } + + fun markAsRead(): ChatMessage { + require(status == Status.SENT) { "메시지가 전송된 상태에서만 읽음 처리가 가능합니다" } + return this.copy( + status = Status.READ, + updatedAt = LocalDateTime.now() + ) + } + + + fun markAsFailed(reason: FailureReason) { + require(status == Status.SENT) { "전송된 상태의 메시지만 실패 처리가 가능합니다" } + this.copy( + status = Status.FAILED, + updatedAt = LocalDateTime.now(), + failureReason = reason + ) + } + +} diff --git a/domain/src/main/kotlin/com/threedays/domain/chat/entity/ChatRoom.kt b/domain/src/main/kotlin/com/threedays/domain/chat/entity/ChatRoom.kt new file mode 100644 index 0000000..fa9ffbe --- /dev/null +++ b/domain/src/main/kotlin/com/threedays/domain/chat/entity/ChatRoom.kt @@ -0,0 +1,19 @@ +package com.threedays.domain.chat.entity + +import com.threedays.domain.connection.entity.Connection +import com.threedays.support.common.base.domain.AggregateRoot +import com.threedays.support.common.base.domain.TypeId +import java.time.LocalDateTime +import java.util.UUID + +data class ChatRoom( + override val id: Id, + val connectionId: Connection.Id, + val members: List, + val createdAt: LocalDateTime = LocalDateTime.now() +) : AggregateRoot() { + + data class Id(override val value: UUID) : TypeId(value) + + +} diff --git a/domain/src/main/kotlin/com/threedays/domain/connection/entity/Connection.kt b/domain/src/main/kotlin/com/threedays/domain/connection/entity/Connection.kt new file mode 100644 index 0000000..f66bead --- /dev/null +++ b/domain/src/main/kotlin/com/threedays/domain/connection/entity/Connection.kt @@ -0,0 +1,13 @@ +package com.threedays.domain.connection.entity + +import com.threedays.support.common.base.domain.AggregateRoot +import com.threedays.support.common.base.domain.UUIDTypeId +import java.util.UUID + +data class Connection( + override val id: Id, +): AggregateRoot() { + + data class Id(override val value: UUID) : UUIDTypeId(value) + +} diff --git a/openapi b/openapi index b0457c3..b4118d6 160000 --- a/openapi +++ b/openapi @@ -1 +1 @@ -Subproject commit b0457c3105b260405e5bb3eb07ad9943525acf34 +Subproject commit b4118d6a2e2cf6d57430fe47d6c4a45b9f9817e8