-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMemberEventListener.java
39 lines (30 loc) · 1.43 KB
/
MemberEventListener.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
package team05.integrated_feed_backend.module.member.event.listener;
import java.time.LocalDateTime;
import org.springframework.context.event.EventListener;
import org.springframework.stereotype.Component;
import lombok.RequiredArgsConstructor;
import team05.integrated_feed_backend.common.util.VerificationCodeGenerator;
import team05.integrated_feed_backend.infra.mail.MailService;
import team05.integrated_feed_backend.module.auth.entity.VerificationCode;
import team05.integrated_feed_backend.module.auth.repository.VerificationCodeRepository;
import team05.integrated_feed_backend.module.member.entity.Member;
import team05.integrated_feed_backend.module.member.event.SignedUpEvent;
@Component
@RequiredArgsConstructor
public class MemberEventListener {
private final MailService mailService;
private final VerificationCodeRepository verificationCodeRepository;
@EventListener
public void handleSignedUpEvent(SignedUpEvent event) {
Member member = event.member();
// 인증 코드 생성
VerificationCode code = createVerificationCode(member);
// 인증 코드 이메일 발송
mailService.sendVerificationCode(member.getEmail(), code.getCode());
}
private VerificationCode createVerificationCode(Member member) {
String code = VerificationCodeGenerator.generateCode();
VerificationCode verificationCode = VerificationCode.of(member, code, LocalDateTime.now());
return verificationCodeRepository.save(verificationCode);
}
}