Skip to content

Commit

Permalink
reactor: 사용자 이름과 이메일에 대한 조건 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
JJ503 committed Jan 3, 2024
1 parent 9f43962 commit 06c13ea
Show file tree
Hide file tree
Showing 15 changed files with 194 additions and 47 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import com.backend.blooming.authentication.infrastructure.oauth.OAuthClient;
import com.backend.blooming.authentication.infrastructure.oauth.OAuthType;
import com.backend.blooming.authentication.infrastructure.oauth.dto.UserInformationDto;
import com.backend.blooming.user.domain.Email;
import com.backend.blooming.user.domain.User;
import com.backend.blooming.user.infrastructure.repository.UserRepository;
import lombok.RequiredArgsConstructor;
Expand Down Expand Up @@ -55,7 +56,7 @@ private User persistUser(final UserInformationDto userInformationDto, final OAut
final User savedUser = User.builder()
.oAuthId(userInformationDto.oAuthId())
.oAuthType(oAuthType)
.email(userInformationDto.email())
.email(new Email(userInformationDto.email()))
.build();

return userRepository.save(savedUser);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,12 @@ public enum ExceptionMessage {
EXPIRED_TOKEN("기한이 만료된 토큰입니다."),
UNSUPPORTED_OAUTH_TYPE("지원하지 않는 소셜 로그인 방식입니다."),

// 사용자 정보
// 사용자
NOT_FOUND_USER("사용자를 조회할 수 없습니다."),
NULL_OR_EMPTY_EMAIL("이메일은 비어있을 수 없습니다."),
LONGER_THAN_MAXIMUM_EMAIL("이메일의 최대 길이를 초과했습니다."),
INVALID_EMAIL_FORMAT("이메일 형식에 어긋났습니다."),


// 테마 색상
UNSUPPORTED_THEME_COLOR("지원하지 않는 테마 색상입니다."),
Expand All @@ -26,8 +30,7 @@ public enum ExceptionMessage {
ALREADY_REQUESTED_FRIEND("이미 친구를 요청한 사용자입니다."),
NOT_FOUND_FRIEND_REQUEST("해당 친구 요청을 조회할 수 없습니다."),
FRIEND_ACCEPTANCE_FORBIDDEN("친구 요청을 수락할 권한이 없습니다."),
DELETE_FRIEND_FORBIDDEN("친구를 삭제할 권한이 없습니다.")
;
DELETE_FRIEND_FORBIDDEN("친구를 삭제할 권한이 없습니다.");

private final String message;
}
44 changes: 44 additions & 0 deletions src/main/java/com/backend/blooming/user/domain/Email.java
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();
}
}
}
13 changes: 9 additions & 4 deletions src/main/java/com/backend/blooming/user/domain/User.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import com.backend.blooming.common.entity.BaseTimeEntity;
import com.backend.blooming.themecolor.domain.ThemeColor;
import jakarta.persistence.Column;
import jakarta.persistence.Embedded;
import jakarta.persistence.Entity;
import jakarta.persistence.EnumType;
import jakarta.persistence.Enumerated;
Expand Down Expand Up @@ -37,10 +38,10 @@ public class User extends BaseTimeEntity {
@Enumerated(EnumType.STRING)
private OAuthType oAuthType;

@Column(nullable = false)
private String email;
@Embedded
private Email email;

@Column(unique = true)
@Column(unique = true, length = 50)
private String name;

@Enumerated(EnumType.STRING)
Expand All @@ -57,7 +58,7 @@ public class User extends BaseTimeEntity {
private User(
final String oAuthId,
final OAuthType oAuthType,
final String email,
final Email email,
final String name,
final ThemeColor color,
final String statusMessage
Expand Down Expand Up @@ -86,6 +87,10 @@ public void updateStatusMessage(final String statusMessage) {
this.statusMessage = statusMessage;
}

public String getEmail() {
return email.getValue();
}

public String getColorName() {
if (color == null) {
return null;
Expand Down
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);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import com.backend.blooming.authentication.infrastructure.oauth.OAuthType;
import com.backend.blooming.authentication.infrastructure.oauth.dto.UserInformationDto;
import com.backend.blooming.authentication.infrastructure.oauth.kakao.dto.KakaoUserInformationDto;
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;
Expand Down Expand Up @@ -36,7 +37,7 @@ void setUpFixture() {
.oAuthType(oauth_타입)
.oAuthId(기존_사용자_소셜_정보.oAuthId())
.name("기존 사용자")
.email(기존_사용자_소셜_정보.email())
.email(new Email(기존_사용자_소셜_정보.email()))
.build();

userRepository.save(기존_사용자);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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(
사용자,
Expand Down
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;
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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(
친구_요청한_사용자,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();

Expand Down
Loading

0 comments on commit 06c13ea

Please sign in to comment.