Skip to content

Commit 0bb5c9e

Browse files
committed
이메일 timeout으로 인한 비동기처리 및 유효성검증
비동기처리로 빠른 timeout오률를 해결합니다.
1 parent 84187f8 commit 0bb5c9e

File tree

4 files changed

+44
-1
lines changed

4 files changed

+44
-1
lines changed

src/main/java/com/example/userservice/domain/mail/service/impl/MailSenderServiceImpl.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
import lombok.extern.slf4j.Slf4j;
1717
import org.springframework.mail.javamail.JavaMailSender;
1818
import org.springframework.mail.javamail.MimeMessageHelper;
19+
import org.springframework.scheduling.annotation.Async;
1920
import org.springframework.stereotype.Service;
2021
import org.springframework.transaction.annotation.Transactional;
2122
import org.thymeleaf.context.Context;
@@ -44,6 +45,7 @@ public class MailSenderServiceImpl implements MailSenderService {
4445

4546

4647
@Override
48+
@Async
4749
public void sendMail(SendMailDto sendMailDto) throws MessagingException {
4850
String email=sendMailDto.getEmail();
4951
Integer randomNumber=getVerificationNumber();
@@ -104,6 +106,8 @@ public void sendVerificationMail(VerificationMailDto verificationMailDto) throws
104106
emailRedisUtil.setListData(email,0,"signupVerifySuccess",60*20L);
105107
}else if(Objects.equals(verifyPurpose, MailPurpose.SUBSCRIBE.toString()) && userInputCode.equals(verificationCode)){
106108
emailRedisUtil.setListData(email,0,"subscriberVerifySuccess",60*20L);
109+
}else{
110+
throw new EmailNotValidException("인증이 유효하지 않습니다");
107111
}
108112
}
109113

@@ -122,7 +126,7 @@ private void emailValidationCheck(String email, String verifyPurpose) {
122126
if(verifyPurpose.equals("SUBSCRIBE")){
123127
Optional<Subscriber> subscriber = subscriberRepository.findByEmail(email);
124128
if(subscriber.isPresent()){
125-
throw new IllegalArgumentException("중복된 구독자입니다.");
129+
throw new DuplicateAccountException("중복된 구독자입니다.");
126130
}
127131

128132
}

src/main/java/com/example/userservice/domain/subscriber/entity/Subscriber.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,15 @@ public class Subscriber extends BaseTimeEntity {
3030
@OneToMany(mappedBy = "subscriber", cascade = CascadeType.ALL, orphanRemoval = true)
3131
private List<Interest> interests = new ArrayList<>();
3232

33+
@Column(nullable = false, columnDefinition = "BOOLEAN DEFAULT FALSE")
34+
private boolean sent; // 이메일 발송 여부 (true: 발송 완료, false: 미발송)
35+
36+
37+
@PrePersist
38+
public void prePersist() {
39+
this.sent = false;
40+
}
41+
3342
public Subscriber(String email) {
3443
this.email = email;
3544
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package com.example.userservice.global.config;
2+
3+
import org.springframework.context.annotation.Configuration;
4+
import org.springframework.scheduling.annotation.EnableAsync;
5+
6+
@Configuration
7+
@EnableAsync
8+
public class AsyncConfig {
9+
}

src/main/java/com/example/userservice/global/exception/GlobalExceptionHandler.java

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,27 @@
2424
@Slf4j
2525
public class GlobalExceptionHandler {
2626

27+
28+
@ExceptionHandler(IllegalArgumentException.class)
29+
protected ResponseEntity<?> illegalArgumentException(IllegalArgumentException ex) {
30+
log.error("handleDuplicateAccountException :: ");
31+
32+
ErrorCode errorCode = ErrorCode.UnAuthorizedException;
33+
34+
ErrorResponse error = ErrorResponse.builder()
35+
.status(errorCode.getStatus().value())
36+
.message(ex.getMessage())
37+
.code(errorCode.getCode())
38+
.build();
39+
40+
CommonResponse response = CommonResponse.builder()
41+
.success(false)
42+
.error(error)
43+
.build();
44+
45+
return new ResponseEntity<>(response, errorCode.getStatus());
46+
}
47+
2748
/**
2849
* 회원가입 시, 회원 계정 정보가 중복 되었을때
2950
*/

0 commit comments

Comments
 (0)