Skip to content

Commit ae904a9

Browse files
authored
Merge pull request #404 from TaskFlow-CLAP/CLAP-321
CLAP-321 이메일 전송 비동기 방식으로 수정 및 토큰 만료 예외처리 수정
2 parents 79ae825 + 9bc3af2 commit ae904a9

File tree

8 files changed

+67
-10
lines changed

8 files changed

+67
-10
lines changed

src/main/java/clap/server/adapter/outbound/jwt/access/AccessTokenProvider.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ public boolean isTokenExpired(String token) {
7171
return claims.getExpiration().before(new Date());
7272
} catch (Exception e) {
7373
log.error("Token is expired: {}", e.getMessage());
74-
throw new JwtException(AuthErrorCode.EMPTY_ACCESS_KEY);
74+
throw new JwtException(AuthErrorCode.EXPIRED_TOKEN);
7575
}
7676
}
7777

src/main/java/clap/server/adapter/outbound/jwt/access/temporary/TemporaryTokenProvider.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ public boolean isTokenExpired(String token) {
7171
return claims.getExpiration().before(new Date());
7272
} catch (Exception e) {
7373
log.error("Token is expired: {}", e.getMessage());
74-
throw new JwtException(AuthErrorCode.EMPTY_ACCESS_KEY);
74+
throw new JwtException(AuthErrorCode.EXPIRED_TOKEN);
7575
}
7676
}
7777

src/main/java/clap/server/adapter/outbound/jwt/refresh/RefreshTokenProvider.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ public boolean isTokenExpired(String token) {
6868
return claims.getExpiration().before(new Date());
6969
} catch (Exception e) {
7070
log.error("Token is expired: {}", e.getMessage());
71-
throw new JwtException(AuthErrorCode.EMPTY_ACCESS_KEY);
71+
throw new JwtException(AuthErrorCode.EXPIRED_TOKEN);
7272
}
7373
}
7474

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
package clap.server.application.service.admin;
2+
3+
import clap.server.application.port.outbound.email.SendEmailPort;
4+
import lombok.RequiredArgsConstructor;
5+
import lombok.extern.slf4j.Slf4j;
6+
import org.springframework.scheduling.annotation.Async;
7+
import org.springframework.stereotype.Service;
8+
9+
import java.util.concurrent.CompletableFuture;
10+
@Slf4j
11+
@Service
12+
@RequiredArgsConstructor
13+
public class SendInvitationEmailService {
14+
private final SendEmailPort sendEmailPort;
15+
16+
@Async("emailExecutor")
17+
public void sendInvitationEmail(String memberEmail, String receiverName, String initialPassword, String userNickname) {
18+
CompletableFuture.runAsync(() -> {
19+
try {
20+
sendEmailPort.sendInvitationEmail(memberEmail, receiverName, initialPassword, userNickname);
21+
} catch (Exception e) {
22+
log.error("Failed to send new password email to: {}", memberEmail, e);
23+
}
24+
}).exceptionally(ex -> {
25+
log.error("Unexpected error occurred while sending new password email", ex);
26+
return null;
27+
});
28+
}
29+
}

src/main/java/clap/server/application/service/admin/SendInvitationService.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
import clap.server.application.port.inbound.admin.SendInvitationUsecase;
55
import clap.server.application.port.outbound.member.CommandMemberPort;
66
import clap.server.application.port.outbound.member.LoadMemberPort;
7-
import clap.server.application.port.outbound.email.SendEmailPort;
87
import clap.server.common.annotation.architecture.ApplicationService;
98
import clap.server.common.utils.InitialPasswordGenerator;
109
import clap.server.domain.model.member.Member;
@@ -19,7 +18,7 @@
1918
public class SendInvitationService implements SendInvitationUsecase {
2019
private final LoadMemberPort loadMemberPort;
2120
private final CommandMemberPort commandMemberPort;
22-
private final SendEmailPort sendEmailPort;
21+
private final SendInvitationEmailService sendInvitationEmailService;
2322
private final InitialPasswordGenerator passwordGenerator;
2423
private final PasswordEncoder passwordEncoder;
2524

@@ -37,7 +36,7 @@ public void sendInvitation(SendInvitationRequest request) {
3736

3837
member.changeToApproveRequested();
3938

40-
sendEmailPort.sendInvitationEmail(
39+
sendInvitationEmailService.sendInvitationEmail(
4140
member.getMemberInfo().getEmail(),
4241
member.getMemberInfo().getName(),
4342
initialPassword,

src/main/java/clap/server/application/service/member/ResetPasswordService.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
import clap.server.application.port.inbound.member.ResetInitialPasswordUsecase;
66
import clap.server.application.port.inbound.member.ResetPasswordUsecase;
77
import clap.server.application.port.inbound.member.SendNewPasswordUsecase;
8-
import clap.server.application.port.outbound.email.SendEmailPort;
98
import clap.server.application.port.outbound.member.CommandMemberPort;
109
import clap.server.application.port.outbound.member.LoadMemberPort;
1110
import clap.server.common.annotation.architecture.ApplicationService;
@@ -28,7 +27,7 @@ class ResetPasswordService implements ResetPasswordUsecase, ResetInitialPassword
2827
private final CommandMemberPort commandMemberPort;
2928
private final LoadMemberPort loadMemberPort;
3029
private final InitialPasswordGenerator initialPasswordGenerator;
31-
private final SendEmailPort sendEmailPort;
30+
private final SendPasswordEmailService sendPasswordEmailService;
3231

3332
@Override
3433
public void resetPassword(Long memberId, String inputPassword) {
@@ -52,7 +51,7 @@ public void sendInitialPassword(SendInitialPasswordRequest request) {
5251
() -> new ApplicationException(MemberErrorCode.MEMBER_NOT_FOUND));
5352

5453
String newPassword = initialPasswordGenerator.generateRandomPassword();
55-
sendEmailPort.sendNewPasswordEmail(request.email(), request.name(), newPassword);
54+
sendPasswordEmailService.sendNewPasswordEmail(request.email(), request.name(), newPassword);
5655
String encodedPassword = passwordEncoder.encode(newPassword);
5756
member.resetPassword(encodedPassword);
5857
commandMemberPort.save(member);
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package clap.server.application.service.member;
2+
3+
import clap.server.application.port.outbound.email.SendEmailPort;
4+
import lombok.RequiredArgsConstructor;
5+
import lombok.extern.slf4j.Slf4j;
6+
import org.springframework.scheduling.annotation.Async;
7+
import org.springframework.stereotype.Service;
8+
9+
import java.util.concurrent.CompletableFuture;
10+
11+
@Slf4j
12+
@Service
13+
@RequiredArgsConstructor
14+
public class SendPasswordEmailService {
15+
private final SendEmailPort sendEmailPort;
16+
17+
@Async("emailExecutor")
18+
public void sendNewPasswordEmail(String email, String name, String newPassword) {
19+
CompletableFuture.runAsync(() -> {
20+
try {
21+
sendEmailPort.sendNewPasswordEmail(email, name, newPassword);
22+
} catch (Exception e) {
23+
log.error("Failed to send new password email to: {}", email, e);
24+
}
25+
}).exceptionally(ex -> {
26+
log.error("Unexpected error occurred while sending new password email", ex);
27+
return null;
28+
});
29+
}
30+
}

src/main/java/clap/server/domain/model/task/Task.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ public void approveTask(Member reviewer, Member processor, LocalDateTime dueDate
101101
}
102102

103103
private static String toTaskCode(Category category) {
104-
return category.getMainCategory().getCode() + LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyMMddHHmm"));
104+
return category.getMainCategory().getCode() + category.getCode() + LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyMMddHHmm"));
105105
}
106106

107107
public void updateProcessorOrder(long newProcessorOrder) {

0 commit comments

Comments
 (0)