Skip to content
This repository has been archived by the owner on Nov 27, 2024. It is now read-only.

Commit

Permalink
코드 리팩토링
Browse files Browse the repository at this point in the history
  • Loading branch information
ori0o0p committed Jan 26, 2024
1 parent fc7912a commit ca86f99
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,27 +27,17 @@ public Mono<AuthCode> findByMail(String mail) {
.code(value).build());
}

public Mono<AuthCode> delete(AuthCode authCode) {
public Mono<Void> delete(AuthCode authCode) {
return redisOperations.delete(AUTHCODE + authCode.getMail())
.map(deleted -> {
if (deleted == 1) {
return authCode;
}
return null;
});
.then();
}

public Mono<AuthCode> save(AuthCode authCode) {
public Mono<Void> save(AuthCode authCode) {
return redisOperations.opsForValue()
.set(AUTHCODE + authCode.getMail(),
authCode.getCode(),
Duration.ofHours(3))
.map(result -> {
if (result) {
return authCode;
}
return null;
});
.then();
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,14 @@ public Mono<Void> execute(AuthCodeRequest request) {
String authCode = getRandomCode();
String mail = request.mail();

return sendMail(mail, authCode)
.doOnNext(mailSender::send)
.then(saveAuthCode(mail, authCode))
.then();
Mono<Void> sendMailMono = sendMail(mail, authCode).subscribeOn(Schedulers.boundedElastic());
Mono<Void> saveAuthCodeMono = saveAuthCode(mail, authCode).subscribeOn(Schedulers.boundedElastic());

return Mono.when(sendMailMono,
saveAuthCodeMono);
}


public Mono<Void> reissue(AuthCodeRequest request) {
return getAuthCode(request.mail())
.flatMap(authCode -> codeRepository.delete(authCode)
Expand All @@ -53,8 +55,8 @@ private Mono<AuthCode> getAuthCode(String mail) {
return codeRepository.findByMail(mail);
}

private Mono<MimeMessage> sendMail(String to, String authCode) {
return Mono.fromCallable(() -> {
private Mono<Void> sendMail(String to, String authCode) {
return Mono.fromRunnable(() -> {
try {
MimeMessage message = mailSender.createMimeMessage();
MimeMessageHelper helper = new MimeMessageHelper(message, true, "UTF-8");
Expand All @@ -64,17 +66,18 @@ private Mono<MimeMessage> sendMail(String to, String authCode) {

String mail = getMailTemplate(authCode);

helper.setText(mail);
helper.setText(mail, true);
helper.setFrom(new InternetAddress(admin, "DSM-MAIL-AUTH"));

return message;
mailSender.send(message);
} catch (MessagingException | UnsupportedEncodingException e) {
throw MailSendFailedException.EXCEPTION;
}
}).subscribeOn(Schedulers.boundedElastic());
});
}

private Mono<AuthCode> saveAuthCode(String to, String authCode) {

private Mono<Void> saveAuthCode(String to, String authCode) {
return codeRepository.save(AuthCode.builder()
.mail(to)
.code(authCode)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ public Mono<Void> filter(ServerWebExchange exchange, WebFilterChain chain) {
} else {
return chain.filter(exchange);
}
});
})
.switchIfEmpty(chain.filter(exchange));
}

private Mono<String> resolveToken(ServerHttpRequest request) {
Expand Down

0 comments on commit ca86f99

Please sign in to comment.