Skip to content

Commit

Permalink
refactor: pr 변경사항 반영
Browse files Browse the repository at this point in the history
  • Loading branch information
seulgi99 committed Jul 30, 2024
1 parent 08ba589 commit feacf8d
Show file tree
Hide file tree
Showing 7 changed files with 46 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import static com.gdschongik.gdsc.global.common.constant.EmailConstant.VERIFICATION_EMAIL_SUBJECT;

import com.gdschongik.gdsc.domain.email.dao.UnivEmailVerificationRepository;
import com.gdschongik.gdsc.domain.email.domain.HongikUnivEmailValidator;
import com.gdschongik.gdsc.domain.email.domain.UnivEmailValidator;
import com.gdschongik.gdsc.domain.email.domain.UnivEmailVerification;
import com.gdschongik.gdsc.domain.member.dao.MemberRepository;
import com.gdschongik.gdsc.domain.member.domain.Member;
Expand All @@ -29,7 +29,7 @@ public class UnivEmailVerificationLinkSendService {
private final UnivEmailVerificationRepository univEmailVerificationRepository;

private final MailSender mailSender;
private final HongikUnivEmailValidator hongikUnivEmailValidator;
private final UnivEmailValidator univEmailValidator;
private final EmailVerificationTokenUtil emailVerificationTokenUtil;
private final VerificationLinkUtil verificationLinkUtil;
private final MemberUtil memberUtil;
Expand All @@ -52,7 +52,7 @@ public class UnivEmailVerificationLinkSendService {
public void send(String univEmail) {
boolean isUnivEmailDuplicate = memberRepository.existsByUnivEmail(univEmail);

hongikUnivEmailValidator.validateSendUnivEmailVerificationLink(univEmail, isUnivEmailDuplicate);
univEmailValidator.validateSendUnivEmailVerificationLink(univEmail, isUnivEmailDuplicate);

String verificationToken = generateVerificationToken(univEmail);
String verificationLink = verificationLinkUtil.createLink(verificationToken);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.gdschongik.gdsc.domain.email.application;

import com.gdschongik.gdsc.domain.email.dao.UnivEmailVerificationRepository;
import com.gdschongik.gdsc.domain.email.domain.HongikUnivEmailValidator;
import com.gdschongik.gdsc.domain.email.domain.UnivEmailValidator;
import com.gdschongik.gdsc.domain.email.domain.UnivEmailVerification;
import com.gdschongik.gdsc.domain.email.dto.request.EmailVerificationTokenDto;
import com.gdschongik.gdsc.domain.email.dto.request.UnivEmailVerificationRequest;
Expand All @@ -23,7 +23,7 @@ public class UnivEmailVerificationService {
private final EmailVerificationTokenUtil emailVerificationTokenUtil;
private final MemberRepository memberRepository;
private final UnivEmailVerificationRepository univEmailVerificationRepository;
private final HongikUnivEmailValidator hongikUnivEmailValidator;
private final UnivEmailValidator univEmailValidator;

@Transactional
public void verifyMemberUnivEmail(UnivEmailVerificationRequest request) {
Expand All @@ -42,7 +42,7 @@ private EmailVerificationTokenDto getEmailVerificationToken(String verificationT
final Optional<UnivEmailVerification> univEmailVerification =
getUnivEmailVerificationFromRedis(emailVerificationTokenDto.memberId());

hongikUnivEmailValidator.validateUnivEmailVerification(univEmailVerification, verificationToken);
univEmailValidator.validateUnivEmailVerification(univEmailVerification, verificationToken);

return emailVerificationTokenDto;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package com.gdschongik.gdsc.domain.email.domain;

import com.gdschongik.gdsc.domain.member.domain.Member;
import com.gdschongik.gdsc.domain.member.dto.UnivVerificationStatus;
import com.gdschongik.gdsc.global.annotation.DomainService;
import java.util.Optional;

@DomainService
public class EmailVerificationStatusService {

public UnivVerificationStatus determineStatus(
Member member, Optional<UnivEmailVerification> univEmailVerification) {
if (member.getAssociateRequirement().isUnivSatisfied()) {
return UnivVerificationStatus.SATISFIED;
} else {
return univEmailVerification.isPresent()
? UnivVerificationStatus.IN_PROGRESS
: UnivVerificationStatus.PENDING;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import java.util.Optional;

@DomainService
public class HongikUnivEmailValidator {
public class UnivEmailValidator {

public void validateSendUnivEmailVerificationLink(String email, boolean isUnivEmailDuplicate) {
if (!email.contains(HONGIK_UNIV_MAIL_DOMAIN)) {
Expand All @@ -34,7 +34,9 @@ public void validateUnivEmailVerification(
Optional<UnivEmailVerification> optionalUnivEmailVerification, String currentToken) {
if (optionalUnivEmailVerification.isEmpty()) {
throw new CustomException(EMAIL_NOT_SENT);
} else if (!optionalUnivEmailVerification.get().getVerificationToken().equals(currentToken)) {
}

if (!optionalUnivEmailVerification.get().getVerificationToken().equals(currentToken)) {
throw new CustomException(EXPIRED_EMAIL_VERIFICATION_TOKEN);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import com.gdschongik.gdsc.domain.auth.dto.AccessTokenDto;
import com.gdschongik.gdsc.domain.auth.dto.RefreshTokenDto;
import com.gdschongik.gdsc.domain.email.application.UnivEmailVerificationService;
import com.gdschongik.gdsc.domain.email.domain.EmailVerificationStatusService;
import com.gdschongik.gdsc.domain.email.domain.UnivEmailVerification;
import com.gdschongik.gdsc.domain.member.dao.MemberRepository;
import com.gdschongik.gdsc.domain.member.domain.Member;
Expand Down Expand Up @@ -41,6 +42,7 @@ public class OnboardingMemberService {
private final JwtService jwtService;
private final MemberRepository memberRepository;
private final EnvironmentUtil environmentUtil;
private final EmailVerificationStatusService emailVerificationStatusService;

public MemberUnivStatusResponse checkUnivVerificationStatus() {
Member currentMember = memberUtil.getCurrentMember();
Expand Down Expand Up @@ -69,7 +71,10 @@ public MemberDashboardResponse getDashboard() {
final Member member = memberUtil.getCurrentMember();
final RecruitmentRound currentRecruitmentRound = onboardingRecruitmentService.findCurrentRecruitmentRound();
final Optional<Membership> myMembership = membershipService.findMyMembership(member, currentRecruitmentRound);
UnivVerificationStatus univVerificationStatus = determineUnivVerificationStatus(member);
final Optional<UnivEmailVerification> univEmailVerification =
univEmailVerificationService.getUnivEmailVerificationFromRedis(member.getId());
UnivVerificationStatus univVerificationStatus =
emailVerificationStatusService.determineStatus(member, univEmailVerification);

return MemberDashboardResponse.of(
member, univVerificationStatus, currentRecruitmentRound, myMembership.orElse(null));
Expand All @@ -93,16 +98,4 @@ private void validateProfile() {
throw new CustomException(FORBIDDEN);
}
}

private UnivVerificationStatus determineUnivVerificationStatus(Member member) {
if (member.getAssociateRequirement().isUnivSatisfied()) {
return UnivVerificationStatus.SATISFIED;
} else {
final Optional<UnivEmailVerification> univEmailVerification =
univEmailVerificationService.getUnivEmailVerificationFromRedis(member.getId());
return univEmailVerification.isPresent()
? UnivVerificationStatus.IN_PROGRESS
: UnivVerificationStatus.PENDING;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public class UnivEmailVerificationServiceTest extends IntegrationTest {
private MailSender mailSender;

@Nested
class 이메일검증시 {
class 재학생_메일_인증시 {

@Test
void 레디스에_이메일인증정보가_존재하지_않으면_실패한다() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.ValueSource;

class HongikUnivEmailValidatorTest {
class UnivEmailValidatorTest {

HongikUnivEmailValidator hongikUnivEmailValidator = new HongikUnivEmailValidator();
UnivEmailValidator univEmailValidator = new UnivEmailValidator();

@Test
@DisplayName("'g.hongik.ac.kr' 도메인을 가진 이메일을 검증할 수 있다.")
Expand All @@ -21,7 +21,7 @@ void validateEmailDomainTest() {
String hongikDomainEmail = "[email protected]";

// when & then
assertThatCode(() -> hongikUnivEmailValidator.validateSendUnivEmailVerificationLink(hongikDomainEmail, false))
assertThatCode(() -> univEmailValidator.validateSendUnivEmailVerificationLink(hongikDomainEmail, false))
.doesNotThrowAnyException();
}

Expand All @@ -30,7 +30,7 @@ void validateEmailDomainTest() {
@DisplayName("'g.hongik.ac.kr'가 아닌 도메인을 가진 이메일을 입력하면 예외를 발생시킨다.")
void validateEmailDomainMismatchTest(String email) {
// when & then
assertThatThrownBy(() -> hongikUnivEmailValidator.validateSendUnivEmailVerificationLink(email, false))
assertThatThrownBy(() -> univEmailValidator.validateSendUnivEmailVerificationLink(email, false))
.isInstanceOf(CustomException.class)
.hasMessage(ErrorCode.UNIV_EMAIL_DOMAIN_MISMATCH.getMessage());
}
Expand All @@ -42,7 +42,7 @@ void validateEmailFormatWithDotsTest() {
String email = "[email protected]";

// when & then
assertThatCode(() -> hongikUnivEmailValidator.validateSendUnivEmailVerificationLink(email, false))
assertThatCode(() -> univEmailValidator.validateSendUnivEmailVerificationLink(email, false))
.doesNotThrowAnyException();
}

Expand All @@ -61,7 +61,7 @@ void validateEmailFormatWithDotsTest() {
@DisplayName("Email의 '@' 앞 부분에 '&', '=', ''', '-', '+', ',', '<', '>'가 포함되는 경우 예외를 발생시킨다.")
void validateEmailFormatMismatchTest(String email) {
// when & then
assertThatThrownBy(() -> hongikUnivEmailValidator.validateSendUnivEmailVerificationLink(email, false))
assertThatThrownBy(() -> univEmailValidator.validateSendUnivEmailVerificationLink(email, false))
.isInstanceOf(CustomException.class)
.hasMessage(ErrorCode.UNIV_EMAIL_FORMAT_MISMATCH.getMessage());
}
Expand All @@ -73,7 +73,7 @@ void validateEmailFormatMismatchWithDotsTest() {
String email = "[email protected]";

// when & then
assertThatThrownBy(() -> hongikUnivEmailValidator.validateSendUnivEmailVerificationLink(email, false))
assertThatThrownBy(() -> univEmailValidator.validateSendUnivEmailVerificationLink(email, false))
.isInstanceOf(CustomException.class)
.hasMessage(ErrorCode.UNIV_EMAIL_FORMAT_MISMATCH.getMessage());
}
Expand All @@ -84,8 +84,7 @@ void validateEmailFormatMismatchWithDotsTest() {
String hongikDomainEmail = "[email protected]";

// when & then
assertThatThrownBy(
() -> hongikUnivEmailValidator.validateSendUnivEmailVerificationLink(hongikDomainEmail, true))
assertThatThrownBy(() -> univEmailValidator.validateSendUnivEmailVerificationLink(hongikDomainEmail, true))
.isInstanceOf(CustomException.class)
.hasMessage(UNIV_EMAIL_ALREADY_SATISFIED.getMessage());
}
Expand Down

0 comments on commit feacf8d

Please sign in to comment.