Skip to content

Commit

Permalink
Member Email 값 객체를 SocialId 값 객체로 변경 (#196)
Browse files Browse the repository at this point in the history
* refactor: Member Email 값 객체를 SocialId 로 변경

* refactor: Member 의 SocialId 컬럼명 수정
  • Loading branch information
hyena0608 authored Aug 3, 2023
1 parent 7a15394 commit afe83da
Show file tree
Hide file tree
Showing 30 changed files with 195 additions and 106 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public enum ClientErrorCode {
JWT_SIGNATURE_IS_WRONG(HttpStatus.BAD_REQUEST, "JW001", "시그니처가 다른 잘못된 JWT 입니다."),
JWT_FORM_IS_WRONG(HttpStatus.BAD_REQUEST, "JW002", "잘못 생성된 JWT 로 디코딩 할 수 없습니다."),
JWT_CLAIM_IS_WRONG(HttpStatus.BAD_REQUEST, "JW003", "JWT 에 기대한 정보를 모두 포함하고 있지 않습니다."),
JWT_CLAIM_EMAIL_IS_WRONG(HttpStatus.BAD_REQUEST, "JW004", "사용자의 잘못된 이메일 정보를 가진 JWT 입니다.");
JWT_CLAIM_SOCIAL_ID_IS_WRONG(HttpStatus.BAD_REQUEST, "JW004", "사용자의 잘못된 소셜 아이디(SocialId) 정보를 가진 JWT 입니다.");

private final HttpStatus httpStatus;
private final String errorCode;
Expand Down
20 changes: 10 additions & 10 deletions backend/baton/src/main/java/touch/baton/domain/member/Member.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import touch.baton.domain.common.BaseEntity;
import touch.baton.domain.member.exception.MemberDomainException;
import touch.baton.domain.member.vo.Company;
import touch.baton.domain.member.vo.Email;
import touch.baton.domain.member.vo.SocialId;
import touch.baton.domain.member.vo.GithubUrl;
import touch.baton.domain.member.vo.ImageUrl;
import touch.baton.domain.member.vo.MemberName;
Expand All @@ -34,7 +34,7 @@ public class Member extends BaseEntity {
private MemberName memberName;

@Embedded
private Email email;
private SocialId socialId;

@Embedded
private OauthId oauthId;
Expand All @@ -50,35 +50,35 @@ public class Member extends BaseEntity {

@Builder
private Member(final MemberName memberName,
final Email email,
final SocialId socialId,
final OauthId oauthId,
final GithubUrl githubUrl,
final Company company,
final ImageUrl imageUrl
) {
this(null, memberName, email, oauthId, githubUrl, company, imageUrl);
this(null, memberName, socialId, oauthId, githubUrl, company, imageUrl);
}

private Member(final Long id,
final MemberName memberName,
final Email email,
final SocialId socialId,
final OauthId oauthId,
final GithubUrl githubUrl,
final Company company,
final ImageUrl imageUrl
) {
validateNotNull(memberName, email, oauthId, githubUrl, company, imageUrl);
validateNotNull(memberName, socialId, oauthId, githubUrl, company, imageUrl);
this.id = id;
this.memberName = memberName;
this.email = email;
this.socialId = socialId;
this.oauthId = oauthId;
this.githubUrl = githubUrl;
this.company = company;
this.imageUrl = imageUrl;
}

private void validateNotNull(final MemberName memberName,
final Email email,
final SocialId socialId,
final OauthId oauthId,
final GithubUrl githubUrl,
final Company company,
Expand All @@ -88,8 +88,8 @@ private void validateNotNull(final MemberName memberName,
throw new MemberDomainException("Member 의 name 은 null 일 수 없습니다.");
}

if (Objects.isNull(email)) {
throw new MemberDomainException("Member 의 email 은 null 일 수 없습니다.");
if (Objects.isNull(socialId)) {
throw new MemberDomainException("Member 의 socialId 은 null 일 수 없습니다.");
}

if (Objects.isNull(oauthId)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,19 @@
@Getter
@NoArgsConstructor(access = PROTECTED)
@Embeddable
public class Email {
public class SocialId {

@Column(name = "email", nullable = false)
@Column(name = "social_id", nullable = false)
private String value;

public Email(final String value) {
public SocialId(final String value) {
validateNotNull(value);
this.value = value;
}

private void validateNotNull(final String value) {
if (Objects.isNull(value)) {
throw new IllegalArgumentException("Email 객체 내부에 email 은 null 일 수 없습니다.");
throw new IllegalArgumentException("SocialId 객체 내부에 value 은 null 일 수 없습니다.");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.NoArgsConstructor;
import touch.baton.domain.member.vo.Email;
import touch.baton.domain.member.vo.SocialId;
import touch.baton.domain.member.vo.GithubUrl;
import touch.baton.domain.member.vo.ImageUrl;
import touch.baton.domain.member.vo.MemberName;
Expand All @@ -24,7 +24,7 @@ public class OauthInformation {

private MemberName memberName;

private Email email;
private SocialId socialId;

private GithubUrl githubUrl;

Expand All @@ -34,14 +34,14 @@ public class OauthInformation {
private OauthInformation(final SocialToken socialToken,
final OauthId oauthId,
final MemberName memberName,
final Email email,
final SocialId socialId,
final GithubUrl githubUrl,
final ImageUrl imageUrl
) {
this.socialToken = socialToken;
this.oauthId = oauthId;
this.memberName = memberName;
this.email = email;
this.socialId = socialId;
this.githubUrl = githubUrl;
this.imageUrl = imageUrl;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,9 @@ public Object resolveArgument(final MethodParameter parameter,

final String token = authHeader.substring(BEARER.length());
final Claims claims = jwtDecoder.parseJwtToken(token);
final String email = claims.get("email", String.class);
final Runner foundRunner = oauthRunnerRepository.joinByMemberEmail(email)
.orElseThrow(() -> new OauthRequestException(ClientErrorCode.JWT_CLAIM_EMAIL_IS_WRONG));
final String socialId = claims.get("socialId", String.class);
final Runner foundRunner = oauthRunnerRepository.joinByMemberSocialId(socialId)
.orElseThrow(() -> new OauthRequestException(ClientErrorCode.JWT_CLAIM_SOCIAL_ID_IS_WRONG));

return foundRunner;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,9 @@ public Object resolveArgument(final MethodParameter parameter,

final String token = authHeader.substring(BEARER.length());
final Claims claims = jwtDecoder.parseJwtToken(token);
final String email = claims.get("email", String.class);
final Supporter foundSupporter = oauthSupporterRepository.joinByMemberEmail(email)
.orElseThrow(() -> new OauthRequestException(ClientErrorCode.JWT_CLAIM_EMAIL_IS_WRONG));
final String socialId = claims.get("socialId", String.class);
final Supporter foundSupporter = oauthSupporterRepository.joinByMemberSocialId(socialId)
.orElseThrow(() -> new OauthRequestException(ClientErrorCode.JWT_CLAIM_SOCIAL_ID_IS_WRONG));

return foundSupporter;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public interface OauthRunnerRepository extends JpaRepository<Runner, Long> {
select r, r.member
from Runner r
join fetch Member m on m.id = r.member.id
where m.email.value = :email
where m.socialId.value = :socialId
""")
Optional<Runner> joinByMemberEmail(@Param("email") final String email);
Optional<Runner> joinByMemberSocialId(@Param("socialId") final String socialId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public interface OauthSupporterRepository extends JpaRepository<Supporter, Long>
select s, s.member
from Supporter s
join fetch Member m on m.id = s.member.id
where m.email.value = :email
where m.socialId.value = :socialId
""")
Optional<Supporter> joinByMemberEmail(@Param("email") final String email);
Optional<Supporter> joinByMemberSocialId(@Param("socialId") final String socialId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -51,14 +51,14 @@ public String login(final OauthType oauthType, final String code) {
}

return jwtEncoder.jwtToken(Map.of(
"email", oauthInformation.getEmail().getValue())
"socialId", oauthInformation.getSocialId().getValue())
);
}

private Member signUpMember(final OauthInformation oauthInformation) {
final Member newMember = Member.builder()
.memberName(oauthInformation.getMemberName())
.email(oauthInformation.getEmail())
.socialId(oauthInformation.getSocialId())
.oauthId(oauthInformation.getOauthId())
.githubUrl(oauthInformation.getGithubUrl())
.company(new Company(""))
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package touch.baton.infra.auth.oauth.github.response;

import com.fasterxml.jackson.databind.annotation.JsonNaming;
import touch.baton.domain.member.vo.Email;
import touch.baton.domain.member.vo.SocialId;
import touch.baton.domain.member.vo.GithubUrl;
import touch.baton.domain.member.vo.ImageUrl;
import touch.baton.domain.member.vo.MemberName;
Expand All @@ -14,7 +14,7 @@
@JsonNaming(SnakeCaseStrategy.class)
public record GithubMemberResponse(String id,
String name,
String email,
String login,
String htmlUrl,
String avatarUrl
) {
Expand All @@ -24,7 +24,7 @@ public OauthInformation toOauthInformation(final String accessToken) {
.socialToken(new SocialToken(accessToken))
.oauthId(new OauthId(id))
.memberName(new MemberName(name))
.email(new Email(email))
.socialId(new SocialId(login))
.githubUrl(new GithubUrl(htmlUrl))
.imageUrl(new ImageUrl(avatarUrl))
.build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import org.junit.jupiter.api.Test;
import touch.baton.domain.member.exception.MemberDomainException;
import touch.baton.domain.member.vo.Company;
import touch.baton.domain.member.vo.Email;
import touch.baton.domain.member.vo.SocialId;
import touch.baton.domain.member.vo.GithubUrl;
import touch.baton.domain.member.vo.ImageUrl;
import touch.baton.domain.member.vo.MemberName;
Expand All @@ -25,7 +25,7 @@ class Create {
void success() {
assertThatCode(() -> Member.builder()
.memberName(new MemberName("헤에디주"))
.email(new Email("[email protected]"))
.socialId(new SocialId("testSocialId"))
.oauthId(new OauthId("dsigjh98gh230gn2oinv913bcuo23nqovbvu93b12voi3bc31j"))
.githubUrl(new GithubUrl("github.com/hyena0608"))
.company(new Company("우아한형제들"))
Expand All @@ -39,7 +39,7 @@ void success() {
void fail_if_name_is_null() {
assertThatThrownBy(() -> Member.builder()
.memberName(null)
.email(new Email("[email protected]"))
.socialId(new SocialId("testSocialId"))
.oauthId(new OauthId("dsigjh98gh230gn2oinv913bcuo23nqovbvu93b12voi3bc31j"))
.githubUrl(new GithubUrl("github.com/hyena0608"))
.company(new Company("우아한형제들"))
Expand All @@ -49,27 +49,27 @@ void fail_if_name_is_null() {
.hasMessage("Member 의 name 은 null 일 수 없습니다.");
}

@DisplayName("이메일에 null 이 들어갈 경우 예외가 발생한다.")
@DisplayName("socialId에 null 이 들어갈 경우 예외가 발생한다.")
@Test
void fail_if_email_is_null() {
void fail_if_socialId_is_null() {
assertThatThrownBy(() -> Member.builder()
.memberName(new MemberName("에단"))
.email(null)
.socialId(null)
.oauthId(new OauthId("dsigjh98gh230gn2oinv913bcuo23nqovbvu93b12voi3bc31j"))
.githubUrl(new GithubUrl("github.com/hyena0608"))
.company(new Company("우아한형제들"))
.imageUrl(new ImageUrl("imageUrl"))
.build()
).isInstanceOf(MemberDomainException.class)
.hasMessage("Member 의 email 은 null 일 수 없습니다.");
.hasMessage("Member 의 socialId 은 null 일 수 없습니다.");
}

@DisplayName("oauth id 에 null 이 들어갈 경우 예외가 발생한다.")
@Test
void fail_if_oauth_id_is_null() {
assertThatThrownBy(() -> Member.builder()
.memberName(new MemberName("에단"))
.email(new Email("[email protected]"))
.socialId(new SocialId("testSocialId"))
.oauthId(null)
.githubUrl(new GithubUrl("github.com/hyena0608"))
.company(new Company("우아한형제들"))
Expand All @@ -84,7 +84,7 @@ void fail_if_oauth_id_is_null() {
void fail_if_github_url_is_null() {
assertThatThrownBy(() -> Member.builder()
.memberName(new MemberName("에단"))
.email(new Email("[email protected]"))
.socialId(new SocialId("testSocialId"))
.oauthId(new OauthId("dsigjh98gh230gn2oinv913bcuo23nqovbvu93b12voi3bc31j"))
.githubUrl(null)
.company(new Company("우아한형제들"))
Expand All @@ -99,7 +99,7 @@ void fail_if_github_url_is_null() {
void fail_if_company_is_null() {
assertThatThrownBy(() -> Member.builder()
.memberName(new MemberName("에단"))
.email(new Email("[email protected]"))
.socialId(new SocialId("testSocialId"))
.oauthId(new OauthId("dsigjh98gh230gn2oinv913bcuo23nqovbvu93b12voi3bc31j"))
.githubUrl(new GithubUrl("github.com/hyena0608"))
.company(null)
Expand All @@ -114,7 +114,7 @@ void fail_if_company_is_null() {
void fail_if_imageUrl_is_null() {
assertThatThrownBy(() -> Member.builder()
.memberName(new MemberName("에단"))
.email(new Email("[email protected]"))
.socialId(new SocialId("testSocialId"))
.oauthId(new OauthId("dsigjh98gh230gn2oinv913bcuo23nqovbvu93b12voi3bc31j"))
.githubUrl(new GithubUrl("github.com/hyena0608"))
.company(new Company("우아한형제들"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@

import static org.assertj.core.api.Assertions.assertThatThrownBy;

class EmailTest {
class SocialIdTest {

@DisplayName("value 가 null 이면 예외가 발생한다.")
@Test
void fail_if_value_is_null() {
assertThatThrownBy(() -> new Email(null))
assertThatThrownBy(() -> new SocialId(null))
.isInstanceOf(IllegalArgumentException.class);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import touch.baton.domain.common.vo.TotalRating;
import touch.baton.domain.member.Member;
import touch.baton.domain.member.vo.Company;
import touch.baton.domain.member.vo.Email;
import touch.baton.domain.member.vo.SocialId;
import touch.baton.domain.member.vo.GithubUrl;
import touch.baton.domain.member.vo.ImageUrl;
import touch.baton.domain.member.vo.MemberName;
Expand All @@ -25,7 +25,7 @@ class Create {

private final Member member = Member.builder()
.memberName(new MemberName("헤에디주"))
.email(new Email("[email protected]"))
.socialId(new SocialId("testSocialId"))
.oauthId(new OauthId("dsigjh98gh230gn2oinv913bcuo23nqovbvu93b12voi3bc31j"))
.githubUrl(new GithubUrl("github.com/hyena0608"))
.company(new Company("우아한형제들"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import touch.baton.domain.member.Member;
import touch.baton.domain.member.repository.MemberRepository;
import touch.baton.domain.member.vo.Company;
import touch.baton.domain.member.vo.Email;
import touch.baton.domain.member.vo.SocialId;
import touch.baton.domain.member.vo.GithubUrl;
import touch.baton.domain.member.vo.ImageUrl;
import touch.baton.domain.member.vo.MemberName;
Expand All @@ -25,7 +25,7 @@
class RunnerRepositoryTest extends RepositoryTestConfig {

private static final MemberName memberName = new MemberName("헤에디주");
private static final Email email = new Email("[email protected]");
private static final SocialId socialId = new SocialId("testSocialId");
private static final OauthId oauthId = new OauthId("dsigjh98gh230gn2oinv913bcuo23nqovbvu93b12voi3bc31j");
private static final GithubUrl githubUrl = new GithubUrl("github.com/hyena0608");
private static final Company company = new Company("우아한형제들");
Expand All @@ -45,7 +45,7 @@ class RunnerRepositoryTest extends RepositoryTestConfig {
void setUp() {
final Member member = Member.builder()
.memberName(memberName)
.email(email)
.socialId(socialId)
.oauthId(oauthId)
.githubUrl(githubUrl)
.company(company)
Expand Down Expand Up @@ -76,7 +76,7 @@ void findByIdJoinMember() {
() -> assertThat(actualMember.getId()).isNotNull(),
() -> assertThat(actualMember.getMemberName()).isEqualTo(memberName),
() -> assertThat(actualMember.getCompany()).isEqualTo(company),
() -> assertThat(actualMember.getEmail()).isEqualTo(email),
() -> assertThat(actualMember.getSocialId()).isEqualTo(socialId),
() -> assertThat(actualMember.getOauthId()).isEqualTo(oauthId),
() -> assertThat(actualMember.getGithubUrl()).isEqualTo(githubUrl)
);
Expand Down
Loading

0 comments on commit afe83da

Please sign in to comment.