|
| 1 | +package com.ururulab.ururu.seller.domain.entity; |
| 2 | + |
| 3 | +import com.ururulab.ururu.global.common.entity.BaseEntity; |
| 4 | +import com.ururulab.ururu.seller.domain.dto.validation.SellerValidationConstants; |
| 5 | +import com.ururulab.ururu.seller.domain.dto.validation.SellerValidationMessages; |
| 6 | +import jakarta.persistence.*; |
| 7 | +import lombok.AccessLevel; |
| 8 | +import lombok.Getter; |
| 9 | +import lombok.NoArgsConstructor; |
| 10 | + |
| 11 | +@Entity |
| 12 | +@Getter |
| 13 | +@Table(name = "Seller") |
| 14 | +@NoArgsConstructor(access = AccessLevel.PROTECTED) |
| 15 | +public class Seller extends BaseEntity { |
| 16 | + |
| 17 | + @Id |
| 18 | + @GeneratedValue(strategy = GenerationType.IDENTITY) |
| 19 | + private Long id; |
| 20 | + |
| 21 | + @Column(length = SellerValidationConstants.NAME_MAX_LENGTH, nullable = false) |
| 22 | + private String name; // 브랜드명 |
| 23 | + |
| 24 | + @Column(length = SellerValidationConstants.BUSINESS_NAME_MAX_LENGTH, nullable = false) |
| 25 | + private String businessName; // 사업자명 |
| 26 | + |
| 27 | + @Column(length = SellerValidationConstants.OWNER_NAME_MAX_LENGTH, nullable = false) |
| 28 | + private String ownerName; // 대표 CEO명 |
| 29 | + |
| 30 | + @Column(length = SellerValidationConstants.BUSINESS_NUMBER_LENGTH, nullable = false) |
| 31 | + private String businessNumber; // 사업자등록번호 |
| 32 | + |
| 33 | + @Column(length = SellerValidationConstants.EMAIL_MAX_LENGTH, nullable = false, unique = true) |
| 34 | + private String email; |
| 35 | + |
| 36 | + @Column(length = 50, nullable = false) |
| 37 | + private String password; // 암호화된 비밀번호 |
| 38 | + |
| 39 | + @Column(length = SellerValidationConstants.PHONE_MAX_LENGTH, nullable = false) |
| 40 | + private String phone; |
| 41 | + |
| 42 | + @Column(length = SellerValidationConstants.IMAGE_MAX_LENGTH) |
| 43 | + private String image; // 브랜드 대표 이미지 |
| 44 | + |
| 45 | + @Column(length = SellerValidationConstants.ADDRESS_MAX_LENGTH, nullable = false) |
| 46 | + private String address1; |
| 47 | + |
| 48 | + @Column(length = SellerValidationConstants.ADDRESS_MAX_LENGTH, nullable = false) |
| 49 | + private String address2; |
| 50 | + |
| 51 | + @Column(length = SellerValidationConstants.MAIL_ORDER_NUMBER_MAX_LENGTH, nullable = false) |
| 52 | + private String mailOrderNumber; // 통신판매업 신고번호 |
| 53 | + |
| 54 | + @Column(nullable = false) |
| 55 | + private Boolean isDeleted = false; |
| 56 | + |
| 57 | + public static Seller of( |
| 58 | + String name, |
| 59 | + String businessName, |
| 60 | + String ownerName, |
| 61 | + String businessNumber, |
| 62 | + String email, |
| 63 | + String password, |
| 64 | + String phone, |
| 65 | + String image, |
| 66 | + String address1, |
| 67 | + String address2, |
| 68 | + String mailOrderNumber |
| 69 | + ) { |
| 70 | + Seller seller = new Seller(); |
| 71 | + seller.name = name; |
| 72 | + seller.businessName = businessName; |
| 73 | + seller.ownerName = ownerName; |
| 74 | + seller.businessNumber = businessNumber; |
| 75 | + seller.email = email; |
| 76 | + seller.password = password; |
| 77 | + seller.phone = phone; |
| 78 | + seller.image = image; |
| 79 | + seller.address1 = address1; |
| 80 | + seller.address2 = address2; |
| 81 | + seller.mailOrderNumber = mailOrderNumber; |
| 82 | + return seller; |
| 83 | + } |
| 84 | + |
| 85 | + public void updateName(final String name) { |
| 86 | + if (name == null || name.trim().isEmpty()) { |
| 87 | + throw new IllegalArgumentException(SellerValidationMessages.NAME_REQUIRED); |
| 88 | + } |
| 89 | + this.name = name.trim(); |
| 90 | + } |
| 91 | + |
| 92 | + public void updateBusinessName(final String businessName) { |
| 93 | + if (businessName == null || businessName.trim().isEmpty()) { |
| 94 | + throw new IllegalArgumentException(SellerValidationMessages.BUSINESS_NAME_REQUIRED); |
| 95 | + } |
| 96 | + this.businessName = businessName.trim(); |
| 97 | + } |
| 98 | + |
| 99 | + public void updateOwnerName(final String ownerName) { |
| 100 | + if (ownerName == null || ownerName.trim().isEmpty()) { |
| 101 | + throw new IllegalArgumentException(SellerValidationMessages.OWNER_NAME_REQUIRED); |
| 102 | + } |
| 103 | + this.ownerName = ownerName.trim(); |
| 104 | + } |
| 105 | + |
| 106 | + public void updatePhone(final String phone) { |
| 107 | + this.phone = phone; |
| 108 | + } |
| 109 | + |
| 110 | + public void updateImage(final String image) { |
| 111 | + this.image = image; |
| 112 | + } |
| 113 | + |
| 114 | + public void updateAddress(final String address1, final String address2) { |
| 115 | + if (address1 == null || address1.trim().isEmpty()) { |
| 116 | + throw new IllegalArgumentException(SellerValidationMessages.ADDRESS1_REQUIRED); |
| 117 | + } |
| 118 | + this.address1 = address1.trim(); |
| 119 | + this.address2 = address2 != null ? address2.trim() : ""; |
| 120 | + } |
| 121 | + |
| 122 | + public void updateMailOrderNumber(final String mailOrderNumber) { |
| 123 | + if (mailOrderNumber == null || mailOrderNumber.trim().isEmpty()) { |
| 124 | + throw new IllegalArgumentException(SellerValidationMessages.MAIL_ORDER_NUMBER_REQUIRED); |
| 125 | + } |
| 126 | + this.mailOrderNumber = mailOrderNumber.trim(); |
| 127 | + } |
| 128 | + |
| 129 | + public void delete() { |
| 130 | + this.isDeleted = true; |
| 131 | + } |
| 132 | +} |
0 commit comments