Skip to content
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
7 changes: 7 additions & 0 deletions docs/seller_diagram.mermaid
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
%% 판매자 도메인 ERD
erDiagram
Seller {
}
SellerRegistrationRequest {
}

18 changes: 18 additions & 0 deletions src/main/kotlin/com/nilgil/commerce/common/Email.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package com.nilgil.commerce.common

import jakarta.persistence.Column
import jakarta.persistence.Embeddable

@Embeddable
data class Email(
@Column(name = "email")
val value: String,
) {
companion object {
private val EMAIL_REGEX = Regex("^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\\.[a-zA-Z]{2,6}$")
}

init {
require(value.matches(EMAIL_REGEX)) { "Invalid email format: $value" }
}
}
18 changes: 18 additions & 0 deletions src/main/kotlin/com/nilgil/commerce/common/PhoneNumber.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package com.nilgil.commerce.common

import jakarta.persistence.Column
import jakarta.persistence.Embeddable

@Embeddable
data class PhoneNumber(
@Column(name = "phone_number")
val value: String,
) {
companion object {
private val PHONE_NUMBER_REGEX = Regex("^01[016789]-\\d{3,4}-\\d{4}$")
}

init {
require(value.matches(PHONE_NUMBER_REGEX)) { "Invalid phone number format: $value" }
}
}
68 changes: 68 additions & 0 deletions src/main/kotlin/com/nilgil/commerce/seller/Seller.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
package com.nilgil.commerce.seller

import com.nilgil.commerce.common.BaseEntity
import com.nilgil.commerce.common.Email
import com.nilgil.commerce.common.PhoneNumber
import jakarta.persistence.Embedded
import jakarta.persistence.Entity
import jakarta.persistence.EnumType
import jakarta.persistence.Enumerated

@Entity
class Seller(
@Embedded
var businessInfo: SellerBusinessInfo,
@Embedded
var contactInfo: SellerContactInfo,
@Embedded
var bankAccount: SellerBankAccount,
var introduction: String?,
var brandLogo: String?,
) : BaseEntity() {
@Enumerated(EnumType.STRING)
var status: SellerStatus = SellerStatus.ACTIVE

fun activate() {
this.status = SellerStatus.ACTIVE
}

fun deactivate() {
this.status = SellerStatus.INACTIVE
}

fun block() {
this.status = SellerStatus.BLOCKED
}

fun unblock() {
this.status = SellerStatus.ACTIVE
}

fun changeBusinessInfo(sellerBusinessInfo: SellerBusinessInfo) {
this.businessInfo = sellerBusinessInfo
}

fun changeContactInfo(contactInfo: SellerContactInfo) {
this.contactInfo = contactInfo
}

fun changeEmail(email: Email) {
this.contactInfo = this.contactInfo.copy(email = email)
}

fun changePhoneNumber(phoneNumber: PhoneNumber) {
this.contactInfo = this.contactInfo.copy(phoneNumber = phoneNumber)
}

fun changeBankAccount(bankAccount: SellerBankAccount) {
this.bankAccount = bankAccount
}

fun changeIntroduction(introduction: String) {
this.introduction = introduction
}
Comment on lines +57 to +63
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

setter 보다 명확한 의미를 가지는 메소드로 뽑아내신 것 좋은 시도 같습니다 👍👍
근데 현재구조라면, 외부에서 seller.backAccount = backAccount 행위를 막을 수 없을 것 같은데요.
코틀린 프로퍼티 setter 접근을 제한하려면 어떻게 하면 좋을까요?

Copy link
Collaborator Author

@nilgil nilgil Jul 7, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Entity
class Seller(
    bankAccount: SellerBankAccount,
) : BaseEntity() {
    @Embedded
    private var _bankAccount: SellerBankAccount = bankAccount

    val bankAccount: SellerBankAccount
        get() = _bankAccount

이런식으로 백킹 프로퍼티를 사용하여 가능할 것 같습니다. 그런데 모든 var에 대해 이렇게 해줘야 할 것 같은데 너무 복잡해질 것 같다는 생각이 듭니다. 세터 사용 금지라는 규약을 정해두고(CI/CD에서 검증 등) 세터를 열어두는 트레이드 오프를 하는 것도 좋아 보입니다.


fun changeBrandLogo(brandLogo: String) {
this.brandLogo = brandLogo
}
}
14 changes: 14 additions & 0 deletions src/main/kotlin/com/nilgil/commerce/seller/SellerBankAccount.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.nilgil.commerce.seller

import jakarta.persistence.Column
import jakarta.persistence.Embeddable

@Embeddable
data class SellerBankAccount(
@Column(name = "bank_name")
val bankName: String,
@Column(name = "bank_account_number")
val accountNumber: String,
@Column(name = "bank_account_holder")
val accountHolder: String,
)
20 changes: 20 additions & 0 deletions src/main/kotlin/com/nilgil/commerce/seller/SellerBusinessInfo.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package com.nilgil.commerce.seller

import jakarta.persistence.Column
import jakarta.persistence.Embeddable

@Embeddable
data class SellerBusinessInfo(
@Column(name = "business_name")
val name: String,
@Column(name = "business_type")
val type: String,
@Column(name = "business_category")
val category: String,
@Column(name = "business_address")
val address: String,
@Column(name = "business_registration_number")
val registrationNumber: String,
@Column(name = "business_registration_certificate")
val registrationCertificate: String,
)
14 changes: 14 additions & 0 deletions src/main/kotlin/com/nilgil/commerce/seller/SellerContactInfo.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.nilgil.commerce.seller

import com.nilgil.commerce.common.Email
import com.nilgil.commerce.common.PhoneNumber
import jakarta.persistence.Embeddable
import jakarta.persistence.Embedded

@Embeddable
data class SellerContactInfo(
@Embedded
val email: Email,
@Embedded
val phoneNumber: PhoneNumber,
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package com.nilgil.commerce.seller

import com.nilgil.commerce.common.BaseEntity
import jakarta.persistence.Embedded
import jakarta.persistence.Entity
import jakarta.persistence.EnumType
import jakarta.persistence.Enumerated

@Entity
class SellerRegistrationRequest(
@Embedded
val businessInfo: SellerBusinessInfo,
@Embedded
val contactInfo: SellerContactInfo,
@Embedded
val bankAccount: SellerBankAccount,
) : BaseEntity() {
@Enumerated(EnumType.STRING)
var status: SellerRegistrationStatus = SellerRegistrationStatus.PENDING

fun approve() {
this.status = SellerRegistrationStatus.APPROVED
}

fun reject() {
this.status = SellerRegistrationStatus.REJECTED
}

fun cancel() {
this.status = SellerRegistrationStatus.CANCELLED
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.nilgil.commerce.seller

enum class SellerRegistrationStatus {
APPROVED,
PENDING,
REJECTED,
CANCELLED,
}
7 changes: 7 additions & 0 deletions src/main/kotlin/com/nilgil/commerce/seller/SellerStatus.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.nilgil.commerce.seller

enum class SellerStatus {
ACTIVE,
INACTIVE,
BLOCKED,
}
Loading