diff --git a/src/main/java/com/gdschongik/gdsc/domain/email/application/UnivEmailVerificationService.java b/src/main/java/com/gdschongik/gdsc/domain/email/application/UnivEmailVerificationService.java index 02bdb2c01..834e4614a 100644 --- a/src/main/java/com/gdschongik/gdsc/domain/email/application/UnivEmailVerificationService.java +++ b/src/main/java/com/gdschongik/gdsc/domain/email/application/UnivEmailVerificationService.java @@ -4,7 +4,6 @@ import static com.gdschongik.gdsc.global.exception.ErrorCode.EXPIRED_EMAIL_VERIFICATION_TOKEN; import com.gdschongik.gdsc.domain.email.dao.UnivEmailVerificationRepository; -import com.gdschongik.gdsc.domain.email.domain.HongikUnivEmailValidator; 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; @@ -27,8 +26,6 @@ public class UnivEmailVerificationService { private final MemberRepository memberRepository; private final UnivEmailVerificationRepository univEmailVerificationRepository; - private final HongikUnivEmailValidator hongikUnivEmailValidator; - @Transactional public void verifyMemberUnivEmail(UnivEmailVerificationRequest request) { EmailVerificationTokenDto emailVerificationToken = getEmailVerificationToken(request.token()); @@ -55,15 +52,16 @@ private Member getMemberById(Long id) { return memberRepository.findById(id).orElseThrow(() -> new CustomException(ErrorCode.MEMBER_NOT_FOUND)); } - // redis 안의 존재하는 메일인증 정보로 검증 + /** + * redis 안의 존재하는 메일인증 정보로 검증 + * 1. 토큰이 비었는데 인증하려할 시 에러 (인증메일을 보내지 않았거나, 만료된 경우) + * 2. 토큰이 redis에 저장된 토큰과 다르면 만료되었다는 에러 (메일 여러번 보낸 경우) + */ private void validateUnivEmailVerification( Optional optionalUnivEmailVerification, String currentToken) { - // 토큰이 비었는데 인증하려할 시 에러 (인증메일을 보내지 않았거나, 만료된 경우) if (optionalUnivEmailVerification.isEmpty()) { throw new CustomException(EMAIL_NOT_SENT); - } - // 토큰이 redis에 저장된 토큰과 다르면 만료되었다는 에러 (메일 여러번 보낸 경우) - else if (!optionalUnivEmailVerification.get().getVerificationToken().equals(currentToken)) { + } else if (!optionalUnivEmailVerification.get().getVerificationToken().equals(currentToken)) { throw new CustomException(EXPIRED_EMAIL_VERIFICATION_TOKEN); } } diff --git a/src/main/java/com/gdschongik/gdsc/domain/member/application/OnboardingMemberService.java b/src/main/java/com/gdschongik/gdsc/domain/member/application/OnboardingMemberService.java index 3567e0d2b..e7eba99de 100644 --- a/src/main/java/com/gdschongik/gdsc/domain/member/application/OnboardingMemberService.java +++ b/src/main/java/com/gdschongik/gdsc/domain/member/application/OnboardingMemberService.java @@ -6,7 +6,6 @@ import com.gdschongik.gdsc.domain.auth.application.JwtService; import com.gdschongik.gdsc.domain.auth.dto.AccessTokenDto; import com.gdschongik.gdsc.domain.auth.dto.RefreshTokenDto; -import com.gdschongik.gdsc.domain.common.model.RequirementStatus; import com.gdschongik.gdsc.domain.email.application.UnivEmailVerificationService; import com.gdschongik.gdsc.domain.email.domain.UnivEmailVerification; import com.gdschongik.gdsc.domain.member.dao.MemberRepository; @@ -70,18 +69,7 @@ public MemberDashboardResponse getDashboard() { final Member member = memberUtil.getCurrentMember(); final RecruitmentRound currentRecruitmentRound = onboardingRecruitmentService.findCurrentRecruitmentRound(); final Optional myMembership = membershipService.findMyMembership(member, currentRecruitmentRound); - - UnivVerificationStatus univVerificationStatus; - - if (member.getAssociateRequirement().getUnivStatus() == RequirementStatus.SATISFIED) { - univVerificationStatus = UnivVerificationStatus.SATISFIED; - } else { - final Optional univEmailVerification = - univEmailVerificationService.getUnivEmailVerificationFromRedis(member.getId()); - univVerificationStatus = univEmailVerification.isPresent() - ? UnivVerificationStatus.IN_PROGRESS - : UnivVerificationStatus.PENDING; - } + UnivVerificationStatus univVerificationStatus = determineUnivVerificationStatus(member); return MemberDashboardResponse.of( member, univVerificationStatus, currentRecruitmentRound, myMembership.orElse(null)); @@ -105,4 +93,16 @@ private void validateProfile() { throw new CustomException(FORBIDDEN); } } + + private UnivVerificationStatus determineUnivVerificationStatus(Member member) { + if (member.getAssociateRequirement().isUnivSatisfied()) { + return UnivVerificationStatus.SATISFIED; + } else { + final Optional univEmailVerification = + univEmailVerificationService.getUnivEmailVerificationFromRedis(member.getId()); + return univEmailVerification.isPresent() + ? UnivVerificationStatus.IN_PROGRESS + : UnivVerificationStatus.PENDING; + } + } } diff --git a/src/main/java/com/gdschongik/gdsc/domain/member/domain/AssociateRequirement.java b/src/main/java/com/gdschongik/gdsc/domain/member/domain/AssociateRequirement.java index 2c09c4153..772d08fa7 100644 --- a/src/main/java/com/gdschongik/gdsc/domain/member/domain/AssociateRequirement.java +++ b/src/main/java/com/gdschongik/gdsc/domain/member/domain/AssociateRequirement.java @@ -73,7 +73,7 @@ public void verifyInfo() { // 데이터 전달 로직 - private boolean isUnivSatisfied() { + public boolean isUnivSatisfied() { return univStatus == SATISFIED; } diff --git a/src/main/java/com/gdschongik/gdsc/domain/member/dto/MemberFullDto.java b/src/main/java/com/gdschongik/gdsc/domain/member/dto/MemberFullDto.java index f9c7f0de6..abfc4b842 100644 --- a/src/main/java/com/gdschongik/gdsc/domain/member/dto/MemberFullDto.java +++ b/src/main/java/com/gdschongik/gdsc/domain/member/dto/MemberFullDto.java @@ -10,7 +10,7 @@ public record MemberFullDto( Long memberId, - @Schema(description = "권한", implementation = MemberRole.class) MemberRole role, + @Schema(description = "멤버 역할", implementation = MemberRole.class) MemberRole role, @Schema(description = "회원정보", implementation = MemberBasicInfoDto.class) MemberBasicInfoDto basicInfo, @Schema(description = "인증상태정보", implementation = MemberAssociateRequirementDto.class) MemberAssociateRequirementDto associateRequirement) { diff --git a/src/main/java/com/gdschongik/gdsc/global/exception/ErrorCode.java b/src/main/java/com/gdschongik/gdsc/global/exception/ErrorCode.java index 339c8f878..de71ee2b6 100644 --- a/src/main/java/com/gdschongik/gdsc/global/exception/ErrorCode.java +++ b/src/main/java/com/gdschongik/gdsc/global/exception/ErrorCode.java @@ -56,7 +56,7 @@ public enum ErrorCode { UNIV_EMAIL_DOMAIN_MISMATCH(HttpStatus.BAD_REQUEST, "재학생 메일의 도메인이 맞지 않습니다."), MESSAGING_EXCEPTION(HttpStatus.BAD_REQUEST, "수신자 이메일이 올바르지 않습니다."), VERIFICATION_CODE_NOT_FOUND(HttpStatus.NOT_FOUND, "재학생 인증 코드가 존재하지 않습니다."), - EMAIL_NOT_SENT(HttpStatus.BAD_REQUEST, "이메일 인증 인증메일이 발송되지 않았습니다."), + EMAIL_NOT_SENT(HttpStatus.BAD_REQUEST, "재학생 인증 메일이 발송되지 않았습니다."), EXPIRED_EMAIL_VERIFICATION_TOKEN(HttpStatus.BAD_REQUEST, "이메일 인증 토큰이 만료되었습니다."), INVALID_EMAIL_VERIFICATION_TOKEN(HttpStatus.UNAUTHORIZED, "유효하지 않은 이메일 인증 토큰입니다."), diff --git a/src/test/java/com/gdschongik/gdsc/domain/email/application/UnivEmailVerificationServiceTest.java b/src/test/java/com/gdschongik/gdsc/domain/email/application/UnivEmailVerificationServiceTest.java index 7dc4b267b..a92cba2f9 100644 --- a/src/test/java/com/gdschongik/gdsc/domain/email/application/UnivEmailVerificationServiceTest.java +++ b/src/test/java/com/gdschongik/gdsc/domain/email/application/UnivEmailVerificationServiceTest.java @@ -59,6 +59,7 @@ class 이메일검증시 { @Test void 인증토큰과_레디스에_존재하는_인증정보의_토큰이_다르면_실패한다() { // given + // TODO: 아래 두줄 createGuestMember로 대체하기 Member member = memberRepository.save(Member.createGuestMember(OAUTH_ID)); logoutAndReloginAs(member.getId(), member.getRole());