Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: 불필요한 member entity equals/hashcode 제거 #146

Merged
merged 1 commit into from
Sep 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@ class Chat(
@Comment("주제")
val subject: Subject,

@ManyToOne(fetch = FetchType.LAZY, optional = true) // NOTE: sessionId 컬럼 제거 시 nullable 제거
@ManyToOne(fetch = FetchType.LAZY) // NOTE: sessionId 컬럼 제거 시 nullable 제거
@JoinColumn(name = "member_id")
@Comment("멤버 아이디")
val member: Member? = null,
val member: Member,

@get:Embedded
val content: ChatContent,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ data class Chats(
}

fun validateMatchMember(member: Member) {
require(chats.all { it.member == member }) { "멤버가 일치하지 않습니다." }
require(chats.all { it.member.equalsId(member) }) { "멤버가 일치하지 않습니다." }
}

fun validateNotUseAllAnswers() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import java.io.Serializable
@Suppress("ktlint:standard:no-blank-line-in-list")
@Entity
@Table(
// TODO: 구글 외 다른 소셜 로그인을 지원한다면 email unique 제약조건을 제거할지 검토 필요
uniqueConstraints = [UniqueConstraint(columnNames = ["email"])],
)
class Member(
Expand All @@ -20,6 +21,7 @@ class Member(
@Comment("이름")
val name: String,

// TODO: 구글 외 다른 소셜 로그인을 지원한다면 email unique 제약조건을 제거할지 검토 필요
@Column(nullable = false, unique = true)
@Comment("이메일")
val email: String,
Expand Down Expand Up @@ -54,24 +56,5 @@ class Member(
}
}

override fun equals(other: Any?): Boolean {
if (this === other) return true
if (javaClass != other?.javaClass) return false

other as Member

if (id != other.id) return false
if (name != other.name) return false
if (email != other.email) return false
if (loginType != other.loginType) return false

return true
}

override fun hashCode(): Int {
var result = name.hashCode()
result = 31 * result + email.hashCode()
result = 31 * result + loginType.hashCode()
return result
}
fun equalsId(other: Member): Boolean = id == other.id
}
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ class MemberScenarioTest(
private val fixtureMonkey = FixtureMonkey.builder().plugin(KotlinPlugin()).build()

@MockBean
lateinit var reactiveMemberChatService: ChatAnswerUseCase
lateinit var chatAnswerUseCase: ChatAnswerUseCase

init {
beforeEach {
Expand Down Expand Up @@ -137,7 +137,7 @@ class MemberScenarioTest(
memberCommandRepository.save(member)
setAuthentication(member)

given { reactiveMemberChatService.answer(any()) }.willReturn {
given { chatAnswerUseCase.answer(any()) }.willReturn {
Flux
.create<ChatResponse?> {
it.next(ChatResponse(listOf(Generation(answer))))
Expand Down