Skip to content

Commit

Permalink
feat(chat): declare chat domain (#43)
Browse files Browse the repository at this point in the history
* feat(chat): declare chat domain

* fix

* fix
  • Loading branch information
waterfogSW authored Dec 19, 2024
1 parent 0837f53 commit 44a8142
Show file tree
Hide file tree
Showing 5 changed files with 103 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -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<ChatMember, ChatMember.Id>() {

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

}
Original file line number Diff line number Diff line change
@@ -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<ChatMessage, ChatMessage.Id>() {

data class Id(override val value: UUID) : TypeId<UUID>(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
)
}

}
Original file line number Diff line number Diff line change
@@ -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<ChatMember>,
val createdAt: LocalDateTime = LocalDateTime.now()
) : AggregateRoot<ChatRoom, ChatRoom.Id>() {

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


}
Original file line number Diff line number Diff line change
@@ -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<Connection, Connection.Id>() {

data class Id(override val value: UUID) : UUIDTypeId(value)

}
2 changes: 1 addition & 1 deletion openapi
Submodule openapi updated 0 files

0 comments on commit 44a8142

Please sign in to comment.