-
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.
feat(chat): declare chat domain (#43)
* feat(chat): declare chat domain * fix * fix
- Loading branch information
1 parent
0837f53
commit 44a8142
Showing
5 changed files
with
103 additions
and
1 deletion.
There are no files selected for viewing
17 changes: 17 additions & 0 deletions
17
domain/src/main/kotlin/com/threedays/domain/chat/entity/ChatMember.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,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) | ||
|
||
} |
53 changes: 53 additions & 0 deletions
53
domain/src/main/kotlin/com/threedays/domain/chat/entity/ChatMessage.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,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 | ||
) | ||
} | ||
|
||
} |
19 changes: 19 additions & 0 deletions
19
domain/src/main/kotlin/com/threedays/domain/chat/entity/ChatRoom.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,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) | ||
|
||
|
||
} |
13 changes: 13 additions & 0 deletions
13
domain/src/main/kotlin/com/threedays/domain/connection/entity/Connection.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,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) | ||
|
||
} |