Skip to content
This repository has been archived by the owner on May 19, 2024. It is now read-only.

Commit

Permalink
[WEAV-350] 채팅 멤버 도메인 설계
Browse files Browse the repository at this point in the history
  • Loading branch information
waterfogSW committed Apr 25, 2024
1 parent 8322aed commit 2cd9cf0
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,21 @@ import java.util.*

data class ChatMember(
override val id: UUID = UuidCreator.create(),
val chatRoomId: UUID,
val userId: UUID,
val meetingTeamId: UUID,
val lastReadMessageId: UUID? = null,
val lastReadAt: LocalDateTime? = null,
) : DomainEntity {

companion object {

fun create(
chatRoomId: UUID,
userId: UUID,
meetingTeamId: UUID,
): ChatMember {
return ChatMember(
chatRoomId = chatRoomId,
userId = userId
userId = userId,
meetingTeamId = meetingTeamId,
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,15 @@ data class ChatRoom(
val members: List<ChatMember> = emptyList(),
) : AggregateRoot {

fun addMember(userId: UUID): ChatRoom {
fun addMember(
userId: UUID,
meetingId: UUID,
): ChatRoom {
val existingMember: ChatMember? = members.find { it.userId == userId }
return if (existingMember != null) {
this
} else {
val newMember: ChatMember = ChatMember.create(this.id, userId)
val newMember: ChatMember = ChatMember.create(userId, meetingId)
this.copy(members = members + newMember)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,10 @@ class ChatRoomTest : DescribeSpec({
// arrange
val chatRoom: ChatRoom = ChatRoomFixtureFactory.create()
val userId: UUID = UuidCreator.create()
val meetingTeamId: UUID = UuidCreator.create()

// act
val newMember: ChatRoom = chatRoom.addMember(userId)
val newMember: ChatRoom = chatRoom.addMember(userId, meetingTeamId)

// assert
newMember.members.size shouldBe 1
Expand All @@ -69,19 +70,19 @@ class ChatRoomTest : DescribeSpec({
context("멤버가 이미 존재하는 경우") {
it("멤버를 추가하지 않는다") {
// arrange
val chatRoomId: UUID = UuidCreator.create()
val userId: UUID = UuidCreator.create()
val meetingTeamId: UUID = UuidCreator.create()

val chatMember: ChatMember = ChatMemberFixtureFactory.create(
chatRoomId = chatRoomId,
userId = userId,
meetingTeamId = meetingTeamId
)
val chatRoom: ChatRoom = ChatRoomFixtureFactory.create(
members = listOf(chatMember)
)

// act
val newMember: ChatRoom = chatRoom.addMember(userId)
val newMember: ChatRoom = chatRoom.addMember(userId, meetingTeamId)

// assert
newMember.members.size shouldBe 1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,19 @@ import java.util.*
object ChatMemberFixtureFactory {

fun create(
chatRoomId: UUID = UuidCreator.create(),
id: UUID = UuidCreator.create(),
userId: UUID = UuidCreator.create(),
meetingTeamId: UUID = UuidCreator.create(),
lastReadMessageId: UUID? = null,
lastReadAt: LocalDateTime? = null,
): ChatMember {
return ChatMember(
chatRoomId = chatRoomId,
id = id,
userId = userId,
meetingTeamId = meetingTeamId,
lastReadMessageId = lastReadMessageId,
lastReadAt = lastReadAt
)
}

}

0 comments on commit 2cd9cf0

Please sign in to comment.