Skip to content

Commit

Permalink
refactor: 재학생 인증 완료 여부에 대한 검증을 도메인 서비스로 이동
Browse files Browse the repository at this point in the history
  • Loading branch information
Sangwook02 committed Jul 19, 2024
1 parent 28cbff3 commit e080cf3
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@

import com.gdschongik.gdsc.domain.member.dao.MemberRepository;
import com.gdschongik.gdsc.domain.member.domain.Member;
import com.gdschongik.gdsc.global.exception.CustomException;
import com.gdschongik.gdsc.global.exception.ErrorCode;
import com.gdschongik.gdsc.global.util.MemberUtil;
import com.gdschongik.gdsc.global.util.email.EmailVerificationTokenUtil;
import com.gdschongik.gdsc.global.util.email.HongikUnivEmailValidator;
Expand All @@ -14,6 +12,7 @@
import java.time.Duration;
import java.util.Optional;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

Expand All @@ -30,6 +29,7 @@ public class UnivEmailVerificationLinkSendService {
private final EmailVerificationTokenUtil emailVerificationTokenUtil;
private final VerificationLinkUtil verificationLinkUtil;
private final MemberUtil memberUtil;

public static final Duration VERIFICATION_TOKEN_TIME_TO_LIVE = Duration.ofMinutes(30);

private static final String NOTIFICATION_MESSAGE =
Expand All @@ -45,14 +45,14 @@ public class UnivEmailVerificationLinkSendService {
""";

public void send(String univEmail) {
hongikUnivEmailValidator.validate(univEmail);
validateUnivEmailNotSatisfied(univEmail);
Optional<Member> member = memberRepository.findByUnivEmail(univEmail);

hongikUnivEmailValidator.validate(univEmail, member);

String verificationToken = generateVerificationToken(univEmail);
String verificationLink = verificationLinkUtil.createLink(verificationToken);
String mailContent = writeMailContentWithVerificationLink(verificationLink);
mailSender.send(univEmail, VERIFICATION_EMAIL_SUBJECT, mailContent);
}

log.info("[UnivEmailVerificationLinkSendService] 학생 인증 메일 발송: univEmail={}", univEmail);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,17 @@
@DomainService
public class HongikUnivEmailValidator {

public void validate(String email) {
public void validate(String email, Optional<Member> optionalMember) {
if (!email.contains(HONGIK_UNIV_MAIL_DOMAIN)) {
throw new CustomException(ErrorCode.UNIV_EMAIL_DOMAIN_MISMATCH);
}

if (!email.matches(HONGIK_EMAIL)) {
throw new CustomException(ErrorCode.UNIV_EMAIL_FORMAT_MISMATCH);
throw new CustomException(UNIV_EMAIL_FORMAT_MISMATCH);
}

if (optionalMember.isPresent()) {
throw new CustomException(UNIV_EMAIL_ALREADY_SATISFIED);
}
}
}

0 comments on commit e080cf3

Please sign in to comment.