-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathEmailTemplateBuilder.java
More file actions
85 lines (78 loc) · 4.25 KB
/
EmailTemplateBuilder.java
File metadata and controls
85 lines (78 loc) · 4.25 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
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.stereotype.Component;
import org.thymeleaf.context.Context;
import org.thymeleaf.spring6.SpringTemplateEngine;
@Component
@RequiredArgsConstructor
public class EmailTemplateBuilder {
private final SpringTemplateEngine templateEngine;
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 알림] 댓글이 작성되었습니다.";
context.setVariable("taskDetailUrl", taskDetailUrl);
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", "http://localhost:5173/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);
}
}