diff --git a/src/main/java/com/fullcar/core/response/ErrorCode.java b/src/main/java/com/fullcar/core/response/ErrorCode.java index 5b1f0fc..0dddfdf 100644 --- a/src/main/java/com/fullcar/core/response/ErrorCode.java +++ b/src/main/java/com/fullcar/core/response/ErrorCode.java @@ -22,7 +22,6 @@ public enum ErrorCode { CANNOT_CHANGE_FORM_STATE(BAD_REQUEST, "카풀에 등록된 운전자만 신청서 수락/거절을 할 수 있습니다."), CANNOT_CLOSE_CARPOOL(BAD_REQUEST, "삭제 권한이 없습니다."), INVALID_FORM_STATE(BAD_REQUEST, "유효하지 않은 신청서 상태입니다."), - EXISTED_CODE_IN_MAIL(BAD_REQUEST, "이미 인증번호를 보냈습니다."), NOT_MATCHED_CODE(BAD_REQUEST, "인증번호가 일치하지 않습니다."), /* 401 UNAUTHORIZED */ diff --git a/src/main/java/com/fullcar/member/domain/mail/Mail.java b/src/main/java/com/fullcar/member/domain/mail/Mail.java index 9480886..fc445b7 100644 --- a/src/main/java/com/fullcar/member/domain/mail/Mail.java +++ b/src/main/java/com/fullcar/member/domain/mail/Mail.java @@ -25,4 +25,8 @@ public class Mail { private MemberId memberId; private Integer code; + + public void updateEmailCode(Integer code) { + this.code = code; + } } diff --git a/src/main/java/com/fullcar/member/infra/MailClient.java b/src/main/java/com/fullcar/member/infra/MailClient.java index 279bfc1..0f64349 100644 --- a/src/main/java/com/fullcar/member/infra/MailClient.java +++ b/src/main/java/com/fullcar/member/infra/MailClient.java @@ -26,6 +26,7 @@ import java.util.Random; @Service +//@Component @RequiredArgsConstructor public class MailClient implements MailService { private final BlacklistRepository blacklistRepository; @@ -41,10 +42,13 @@ public void sendMail(Member member, EmailRequestDto emailRequestDto) { String emailDomain = email.substring(email.lastIndexOf("@")+1); blacklistRepository.findByEmailThrow(emailDomain); - if (mailRepository.findByMemberId(member.getId()) != null) { - throw new CustomException(ErrorCode.EXISTED_CODE_IN_MAIL); + Mail mail = mailRepository.findByMemberId(member.getId()); + if (mail != null) { + mail.updateEmailCode(authNum); + } + else { + mailRepository.saveAndFlush(mailMapper.toEntity(member, authNum)); } - mailRepository.saveAndFlush(mailMapper.toEntity(member, authNum)); EmailMessage emailMessage = mailMapper.toMessageEntity(emailRequestDto); MimeMessage mimeMessage = javaMailSender.createMimeMessage();