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 f0a3fbd commit 8322aed
Show file tree
Hide file tree
Showing 5 changed files with 107 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package com.studentcenter.weave.domain.chat.entity

import com.studentcenter.weave.domain.common.DomainEntity
import com.studentcenter.weave.support.common.uuid.UuidCreator
import java.time.LocalDateTime
import java.util.*

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

companion object {

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

}

}
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,19 @@ data class ChatRoom(
val receivingTeamId: UUID,
val requestingTeamId: UUID,
val createdAt: LocalDateTime = LocalDateTime.now(),
val members: List<ChatMember> = emptyList(),
) : AggregateRoot {

fun addMember(userId: UUID): ChatRoom {
val existingMember: ChatMember? = members.find { it.userId == userId }
return if (existingMember != null) {
this
} else {
val newMember: ChatMember = ChatMember.create(this.id, userId)
this.copy(members = members + newMember)
}
}

companion object {

fun create(meeting: Meeting): ChatRoom {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,18 @@ package com.studentcenter.weave.domain.chat.entity

import com.studentcenter.weave.domain.meeting.entity.MeetingFixtureFactory
import com.studentcenter.weave.domain.meeting.enums.MeetingStatus
import com.studentcenter.weave.support.common.uuid.UuidCreator
import io.kotest.assertions.throwables.shouldThrow
import io.kotest.core.annotation.DisplayName
import io.kotest.core.spec.style.DescribeSpec
import io.kotest.matchers.shouldBe
import java.util.*


@DisplayName("ChatRoomTest")
class ChatRoomTest : DescribeSpec({

describe("채팅방 생성 테스트") {
describe("채팅방 생성") {
context("미팅이 매칭된 상태일 경우") {
it("미팅 팀을 통해 채팅방을 생성한다") {
// arrange
Expand Down Expand Up @@ -49,4 +51,42 @@ class ChatRoomTest : DescribeSpec({
}
}

describe("채팅 멤버 추가") {
context("멤버가 존재하지 않는 경우") {
it("멤버를 추가한다") {
// arrange
val chatRoom: ChatRoom = ChatRoomFixtureFactory.create()
val userId: UUID = UuidCreator.create()

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

// assert
newMember.members.size shouldBe 1
}
}

context("멤버가 이미 존재하는 경우") {
it("멤버를 추가하지 않는다") {
// arrange
val chatRoomId: UUID = UuidCreator.create()
val userId: UUID = UuidCreator.create()

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

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

// assert
newMember.members.size shouldBe 1
}
}
}

})
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package com.studentcenter.weave.domain.chat.entity

import com.studentcenter.weave.support.common.uuid.UuidCreator
import java.time.LocalDateTime
import java.util.*

object ChatMemberFixtureFactory {

fun create(
chatRoomId: UUID = UuidCreator.create(),
userId: UUID = UuidCreator.create(),
lastReadMessageId: UUID? = null,
lastReadAt: LocalDateTime? = null,
): ChatMember {
return ChatMember(
chatRoomId = chatRoomId,
userId = userId,
lastReadMessageId = lastReadMessageId,
lastReadAt = lastReadAt
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,16 @@ object ChatRoomFixtureFactory {
requestingTeamId: UUID = UuidCreator.create(),
receivingTeamId: UUID = UuidCreator.create(),
createdAt: LocalDateTime = LocalDateTime.now(),
members: List<ChatMember> = emptyList(),
): ChatRoom {
return ChatRoom(
id = id,
meetingId = meetingId,
requestingTeamId = requestingTeamId,
receivingTeamId = receivingTeamId,
createdAt = createdAt,
members = members
)

}

}

0 comments on commit 8322aed

Please sign in to comment.