22
33import com .back .domain .member .member .email .EmailService ;
44import com .back .global .exception .ServiceException ;
5- import lombok .RequiredArgsConstructor ;
65import lombok .extern .slf4j .Slf4j ;
6+ import org .springframework .beans .factory .annotation .Autowired ;
77import org .springframework .stereotype .Service ;
88
99import java .security .SecureRandom ;
1010import java .time .Duration ;
1111import java .util .Optional ;
1212
1313@ Service
14- @ RequiredArgsConstructor
1514@ Slf4j
1615public class EmailVerificationService {
1716 private final VerificationCodeStore codeStore ;
18- private final EmailService emailService ;
17+ private final Optional < EmailService > emailService ;
1918 private static final Duration CODE_TTL = Duration .ofMinutes (5 );
2019 private static final SecureRandom random = new SecureRandom ();
2120
21+ public EmailVerificationService (VerificationCodeStore codeStore ,
22+ @ Autowired (required = false ) EmailService emailService ) {
23+ this .codeStore = codeStore ;
24+ this .emailService = Optional .ofNullable (emailService );
25+ }
26+
2227 public String generateAndSendCode (String email ) {
2328 // 6자리 랜덤 코드 생성
2429 String code = String .format ("%06d" , random .nextInt (1000000 ));
2530
2631 // 저장
2732 codeStore .saveCode (email , code , CODE_TTL );
2833
29- // 이메일 발송
30- emailService .sendVerificationCode (email , code );
34+ // 이메일 발송 (EmailService가 있을 때만)
35+ emailService .ifPresentOrElse (
36+ service -> service .sendVerificationCode (email , code ),
37+ () -> log .info ("EmailService not available - verification code: {}" , code )
38+ );
3139 log .info ("Generated and sent verification code for {}: {}" , email , code );
3240
3341 return code ; // 테스트용으로 반환 (실제로는 이메일로만 전송)
@@ -48,4 +56,4 @@ public void verifyCode(String email, String inputCode) {
4856 codeStore .deleteCode (email );
4957 log .info ("Email verification successful for: {}" , email );
5058 }
51- }
59+ }
0 commit comments