-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathEmailTemplateBuilder.java
More file actions
101 lines (92 loc) · 5.14 KB
/
EmailTemplateBuilder.java
File metadata and controls
101 lines (92 loc) · 5.14 KB
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
package clap.server.adapter.outbound.api;
import clap.server.adapter.outbound.api.dto.EmailTemplate;
import clap.server.adapter.outbound.api.dto.PushNotificationTemplate;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
import org.thymeleaf.context.Context;
import org.thymeleaf.spring6.SpringTemplateEngine;
@Component
@RequiredArgsConstructor
public class EmailTemplateBuilder {
private final SpringTemplateEngine templateEngine;
@Value("${redirect.url.login}")
private String REDIRECT_URL_LOGIN;
public EmailTemplate createWebhookTemplate(PushNotificationTemplate request, String taskDetailUrl) {
Context context = new Context();
String templateName = "";
String subject = "";
switch (request.notificationType()) {
case TASK_REQUESTED:
templateName = "task-request";
subject = "[TaskFlow] 신규 작업 "+ request.taskName()+ "이 요청되었습니다.";
context.setVariable("taskDetailUrl", taskDetailUrl);
context.setVariable("receiverName", request.senderName());
context.setVariable("title", request.taskName());
break;
case STATUS_SWITCHED:
templateName = "status-switched";
subject = "[TaskFlow] "+ request.taskName()+ " 작업의 상태가 " + request.message() + "으로 변경되었습니다.";
context.setVariable("taskDetailUrl", taskDetailUrl);
context.setVariable("receiverName", request.senderName());
context.setVariable("title", request.taskName());
context.setVariable("status", request.message());
break;
case PROCESSOR_CHANGED:
templateName = "processor-changed";
subject = "[TaskFlow] "+ request.taskName()+ " 작업의 담당자가 " + request.message() + "으로 변경되었습니다.";
context.setVariable("taskDetailUrl", taskDetailUrl);
context.setVariable("processorName", request.message());
context.setVariable("title", request.taskName());
break;
case PROCESSOR_ASSIGNED:
templateName = "processor-assigned";
subject = "[TaskFlow] "+ request.taskName()+ " 작업의 담당자가 " + request.message() + "으로 선정되었습니다..";
context.setVariable("taskDetailUrl", taskDetailUrl);
context.setVariable("processorName", request.message());
context.setVariable("title", request.taskName());
break;
case COMMENT:
templateName = "comment";
subject = "[TaskFlow] " + request.taskName() + " 작업에 " + request.commenterName() + "님이 댓글을 작성하였습니다";
context.setVariable("taskDetailUrl", taskDetailUrl);
context.setVariable("commenter", request.commenterName());
context.setVariable("comment", request.message());
context.setVariable("title", request.taskName());
break;
}
String body = templateEngine.process(templateName, context);
return new EmailTemplate(request.email(), subject, body);
}
public EmailTemplate createInvitationTemplate(String receiver, String receiverName,
String initialPassword, String userNickname) {
Context context = new Context();
String templateName = "invitation";
String subject = "[TaskFlow 초대] 회원가입을 환영합니다.";
context.setVariable("userNickname", userNickname);
context.setVariable("invitationLink", REDIRECT_URL_LOGIN);
context.setVariable("initialPassword", initialPassword);
context.setVariable("receiverName", receiverName);
String body = templateEngine.process(templateName, context);
return new EmailTemplate(receiver, subject, body);
}
public EmailTemplate createVerificationCodeTemplate(String receiver, String receiverName, String verificationCode) {
Context context = new Context();
String templateName = "verification";
String subject = "[TaskFlow] 비밀번호 재설정 인증 번호";
context.setVariable("verificationCode", verificationCode);
context.setVariable("receiverName", receiverName);
String body = templateEngine.process(templateName, context);
return new EmailTemplate(receiver, subject, body);
}
public EmailTemplate createNewPasswordTemplate(String receiver, String receiverName, String newPassword) {
Context context = new Context();
String templateName = "new-password";
String subject = "[TaskFlow] 비밀번호 재설정";
context.setVariable("loginLink", "http://localhost:5173/login");
context.setVariable("newPassword", newPassword);
context.setVariable("receiverName", receiverName);
String body = templateEngine.process(templateName, context);
return new EmailTemplate(receiver, subject, body);
}
}