-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
15 changed files
with
194 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package com.backend.blooming.user.domain; | ||
|
||
import com.backend.blooming.user.domain.exception.MemberException; | ||
import jakarta.persistence.Column; | ||
import jakarta.persistence.Embeddable; | ||
import lombok.AccessLevel; | ||
import lombok.EqualsAndHashCode; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
import lombok.ToString; | ||
|
||
import java.util.regex.Pattern; | ||
|
||
@Embeddable | ||
@NoArgsConstructor(access = AccessLevel.PROTECTED) | ||
@Getter | ||
@EqualsAndHashCode | ||
@ToString | ||
public class Email { | ||
// TODO: 1/3/24 [고민] vo 패키지로 묶는 것이 더 좋을까요? | ||
|
||
private static final int MAX_LENGTH = 50; | ||
private static final String PATTERN = "^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\\.[a-zA-Z]{2,}$"; | ||
|
||
@Column(name = "email", length = MAX_LENGTH, nullable = false) | ||
private String value; | ||
|
||
public Email(final String value) { | ||
validateValue(value); | ||
this.value = value; | ||
} | ||
|
||
private void validateValue(final String value) { | ||
if (value == null || value.isEmpty()) { | ||
throw new MemberException.NullOrEmptyEmailException(); | ||
} | ||
if (value.length() > MAX_LENGTH) { | ||
throw new MemberException.LongerThanMaximumEmailLengthException(); | ||
} | ||
if (!Pattern.matches(PATTERN, value)) { | ||
throw new MemberException.InvalidEmailFormatException(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
src/main/java/com/backend/blooming/user/domain/exception/MemberException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package com.backend.blooming.user.domain.exception; | ||
|
||
import com.backend.blooming.exception.BloomingException; | ||
import com.backend.blooming.exception.ExceptionMessage; | ||
|
||
public class MemberException extends BloomingException { | ||
|
||
private MemberException(final ExceptionMessage exceptionMessage) { | ||
super(exceptionMessage); | ||
} | ||
|
||
public static class NullOrEmptyEmailException extends MemberException { | ||
|
||
public NullOrEmptyEmailException() { | ||
super(ExceptionMessage.NULL_OR_EMPTY_EMAIL); | ||
} | ||
} | ||
|
||
public static class LongerThanMaximumEmailLengthException extends MemberException { | ||
|
||
public LongerThanMaximumEmailLengthException() { | ||
super(ExceptionMessage.LONGER_THAN_MAXIMUM_EMAIL); | ||
} | ||
} | ||
|
||
public static class InvalidEmailFormatException extends MemberException { | ||
|
||
public InvalidEmailFormatException() { | ||
super(ExceptionMessage.INVALID_EMAIL_FORMAT); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,7 @@ | |
import com.backend.blooming.friend.application.dto.ReadFriendsDto; | ||
import com.backend.blooming.friend.domain.Friend; | ||
import com.backend.blooming.friend.infrastructure.repository.FriendRepository; | ||
import com.backend.blooming.user.domain.Email; | ||
import com.backend.blooming.user.domain.User; | ||
import com.backend.blooming.user.infrastructure.repository.UserRepository; | ||
import org.junit.jupiter.api.BeforeEach; | ||
|
@@ -45,55 +46,55 @@ void setUpFixture() { | |
.oAuthId("12345") | ||
.oAuthType(OAuthType.KAKAO) | ||
.name("사용자1") | ||
.email("[email protected]") | ||
.email(new Email("[email protected]")) | ||
.build(); | ||
final User 친구_요청할_사용자 = User.builder() | ||
.oAuthId("12346") | ||
.oAuthType(OAuthType.KAKAO) | ||
.name("사용자2") | ||
.email("[email protected]") | ||
.email(new Email("[email protected]")) | ||
.build(); | ||
final User 친구_요청을_보낸_사용자 = User.builder() | ||
.oAuthId("12347") | ||
.oAuthType(OAuthType.KAKAO) | ||
.name("사용자3") | ||
.email("[email protected]") | ||
.email(new Email("[email protected]")) | ||
.build(); | ||
final User 이미_친구_요청을_받은_사용자 = User.builder() | ||
.oAuthId("12348") | ||
.oAuthType(OAuthType.KAKAO) | ||
.name("사용자4") | ||
.email("[email protected]") | ||
.email(new Email("[email protected]")) | ||
.build(); | ||
final User 친구_요청을_받은_사용자2 = User.builder() | ||
.oAuthId("12349") | ||
.oAuthType(OAuthType.KAKAO) | ||
.name("사용자5") | ||
.email("[email protected]") | ||
.email(new Email("[email protected]")) | ||
.build(); | ||
final User 친구_요청을_받은_사용자3 = User.builder() | ||
.oAuthId("12350") | ||
.oAuthType(OAuthType.KAKAO) | ||
.name("사용자6") | ||
.email("[email protected]") | ||
.email(new Email("[email protected]")) | ||
.build(); | ||
final User 친구인_사용자1 = User.builder() | ||
.oAuthId("23456") | ||
.oAuthType(OAuthType.KAKAO) | ||
.name("친구1") | ||
.email("[email protected]") | ||
.email(new Email("[email protected]")) | ||
.build(); | ||
final User 친구인_사용자2 = User.builder() | ||
.oAuthId("23457") | ||
.oAuthType(OAuthType.KAKAO) | ||
.name("친구2") | ||
.email("[email protected]") | ||
.email(new Email("[email protected]")) | ||
.build(); | ||
final User 친구인_사용자3 = User.builder() | ||
.oAuthId("23458") | ||
.oAuthType(OAuthType.KAKAO) | ||
.name("친구3") | ||
.email("[email protected]") | ||
.email(new Email("[email protected]")) | ||
.build(); | ||
userRepository.saveAll(List.of( | ||
사용자, | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
package com.backend.blooming.friend.domain; | ||
|
||
import com.backend.blooming.authentication.infrastructure.oauth.OAuthType; | ||
import com.backend.blooming.user.domain.Email; | ||
import com.backend.blooming.user.domain.User; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.springframework.test.util.ReflectionTestUtils; | ||
|
@@ -12,19 +13,19 @@ public class FriendTestFixture { | |
.oAuthId("12345") | ||
.oAuthType(OAuthType.KAKAO) | ||
.name("사용자1") | ||
.email("[email protected]") | ||
.email(new Email("[email protected]")) | ||
.build(); | ||
protected static User 친구_요청을_받은_사용자 = User.builder() | ||
.oAuthId("12346") | ||
.oAuthType(OAuthType.KAKAO) | ||
.name("사용자2") | ||
.email("[email protected]") | ||
.email(new Email("[email protected]")) | ||
.build(); | ||
protected static User 친구_요청과_상관없는_사용자 = User.builder() | ||
.oAuthId("12347") | ||
.oAuthType(OAuthType.KAKAO) | ||
.name("사용자3") | ||
.email("[email protected]") | ||
.email(new Email("[email protected]")) | ||
.build(); | ||
|
||
@BeforeEach | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,7 @@ | |
|
||
import com.backend.blooming.authentication.infrastructure.oauth.OAuthType; | ||
import com.backend.blooming.friend.domain.Friend; | ||
import com.backend.blooming.user.domain.Email; | ||
import com.backend.blooming.user.domain.User; | ||
import com.backend.blooming.user.infrastructure.repository.UserRepository; | ||
import org.junit.jupiter.api.BeforeEach; | ||
|
@@ -39,49 +40,49 @@ void setUpFixture() { | |
.oAuthId("12345") | ||
.oAuthType(OAuthType.KAKAO) | ||
.name("사용자1") | ||
.email("[email protected]") | ||
.email(new Email("[email protected]")) | ||
.build(); | ||
이미_친구_요청_받은_사용자 = User.builder() | ||
.oAuthId("12346") | ||
.oAuthType(OAuthType.KAKAO) | ||
.name("사용자2") | ||
.email("[email protected]") | ||
.email(new Email("[email protected]")) | ||
.build(); | ||
친구_요청을_받은적_없는_사용자 = User.builder() | ||
.oAuthId("12347") | ||
.oAuthType(OAuthType.KAKAO) | ||
.name("사용자3") | ||
.email("[email protected]") | ||
.email(new Email("[email protected]")) | ||
.build(); | ||
final User 친구_요청을_받은_사용자2 = User.builder() | ||
.oAuthId("12348") | ||
.oAuthType(OAuthType.KAKAO) | ||
.name("사용자4") | ||
.email("[email protected]") | ||
.email(new Email("[email protected]")) | ||
.build(); | ||
final User 친구_요청을_받은_사용자3 = User.builder() | ||
.oAuthId("12349") | ||
.oAuthType(OAuthType.KAKAO) | ||
.name("사용자5") | ||
.email("[email protected]") | ||
.email(new Email("[email protected]")) | ||
.build(); | ||
final User 친구인_사용자1 = User.builder() | ||
.oAuthId("23456") | ||
.oAuthType(OAuthType.KAKAO) | ||
.name("친구1") | ||
.email("[email protected]") | ||
.email(new Email("[email protected]")) | ||
.build(); | ||
final User 친구인_사용자2 = User.builder() | ||
.oAuthId("23457") | ||
.oAuthType(OAuthType.KAKAO) | ||
.name("친구2") | ||
.email("[email protected]") | ||
.email(new Email("[email protected]")) | ||
.build(); | ||
final User 친구인_사용자3 = User.builder() | ||
.oAuthId("23458") | ||
.oAuthType(OAuthType.KAKAO) | ||
.name("친구3") | ||
.email("[email protected]") | ||
.email(new Email("[email protected]")) | ||
.build(); | ||
userRepository.saveAll(List.of( | ||
친구_요청한_사용자, | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,6 +5,7 @@ | |
import com.backend.blooming.friend.infrastructure.repository.FriendRepository; | ||
import com.backend.blooming.themecolor.domain.ThemeColor; | ||
import com.backend.blooming.user.application.dto.UpdateUserDto; | ||
import com.backend.blooming.user.domain.Email; | ||
import com.backend.blooming.user.domain.User; | ||
import com.backend.blooming.user.infrastructure.repository.UserRepository; | ||
import org.junit.jupiter.api.BeforeEach; | ||
|
@@ -46,27 +47,27 @@ void setUpFixture() { | |
.oAuthId("12345") | ||
.oAuthType(OAuthType.KAKAO) | ||
.name("사용자") | ||
.email("[email protected]") | ||
.email(new Email("[email protected]")) | ||
.color(ThemeColor.BEIGE) | ||
.statusMessage("기존 상태 메시지") | ||
.build(); | ||
친구인_사용자 = User.builder() | ||
.oAuthId("12346") | ||
.oAuthType(OAuthType.KAKAO) | ||
.name("사용자2") | ||
.email("[email protected]") | ||
.email(new Email("[email protected]")) | ||
.build(); | ||
친구가_아닌_사용자 = User.builder() | ||
.oAuthId("12347") | ||
.oAuthType(OAuthType.KAKAO) | ||
.name("사용자3") | ||
.email("[email protected]") | ||
.email(new Email("[email protected]")) | ||
.build(); | ||
final User 삭제한_사용자 = User.builder() | ||
.oAuthId("12348") | ||
.oAuthType(OAuthType.KAKAO) | ||
.name("삭제한 사용자") | ||
.email("[email protected]") | ||
.email(new Email("[email protected]")) | ||
.build(); | ||
삭제한_사용자.delete(); | ||
|
||
|
Oops, something went wrong.