-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathSendNotificationService.java
More file actions
106 lines (86 loc) · 4.32 KB
/
SendNotificationService.java
File metadata and controls
106 lines (86 loc) · 4.32 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
102
103
104
105
106
package clap.server.application.service.webhook;
import clap.server.adapter.outbound.api.dto.PushNotificationTemplate;
import clap.server.adapter.outbound.persistense.entity.notification.constant.NotificationType;
import clap.server.application.port.outbound.notification.CommandNotificationPort;
import clap.server.common.annotation.architecture.ApplicationService;
import clap.server.domain.model.member.Member;
import clap.server.domain.model.notification.Notification;
import clap.server.domain.model.task.Task;
import lombok.RequiredArgsConstructor;
import org.springframework.scheduling.annotation.Async;
import java.util.concurrent.CompletableFuture;
import static clap.server.domain.model.notification.Notification.createTaskNotification;
@ApplicationService
@RequiredArgsConstructor
public class SendNotificationService {
//private final SendSseService sendSseService;
private final SendAgitService sendAgitService;
private final SendWebhookEmailService sendWebhookEmailService;
private final SendKaKaoWorkService sendKaKaoWorkService;
private final CommandNotificationPort commandNotificationPort;
@Async("notificationExecutor")
public void sendPushNotification(Member receiver, NotificationType notificationType,
Task task, String message, String commenterName, Boolean isManager) {
String email = receiver.getMemberInfo().getEmail();
String taskTitle = task.getTitle();
String requesterNickname = task.getRequester().getNickname();
String taskDetailUrl = extractTaskUrl(notificationType, task, isManager);
Notification notification = createTaskNotification(task, receiver, notificationType, message, taskTitle);
PushNotificationTemplate pushNotificationTemplate = new PushNotificationTemplate(
email, notificationType, taskTitle, requesterNickname, message, commenterName
);
CompletableFuture<Void> saveNotification = CompletableFuture.runAsync(() -> {
commandNotificationPort.save(notification);
});
CompletableFuture<Void> sendEmailFuture = CompletableFuture.runAsync(() -> {
if (receiver.getEmailNotificationEnabled()) {
sendWebhookEmailService.send(pushNotificationTemplate, taskDetailUrl);
}
});
CompletableFuture<Void> sendKakaoWorkFuture = CompletableFuture.runAsync(() -> {
if (receiver.getKakaoworkNotificationEnabled()) {
sendKaKaoWorkService.send(pushNotificationTemplate, taskDetailUrl);
}
});
//Todo : SSE 구현시 추가
//SseRequest sseRequest = new SseRequest(
// taskTitle,
// notificationType,
// receiver.getMemberId(),
// message
//);
//Todo : SSE 구현시 추가
//CompletableFuture<Void> sendSseFuture = CompletableFuture.runAsync(() -> {
// sendSsePort.send(sseRequest);
//});
CompletableFuture<Void> allOf = CompletableFuture.allOf(saveNotification,
sendEmailFuture, sendKakaoWorkFuture);
allOf.join();
}
@Async("notificationExecutor")
public void sendAgitNotification(NotificationType notificationType,
Task task, String message, String commenterName) {
PushNotificationTemplate pushNotificationTemplate = new PushNotificationTemplate(
null,
notificationType,
task.getTitle(),
task.getRequester().getNickname(),
message,
commenterName
);
String taskDetailUrl = extractTaskUrl(notificationType, task, true);
sendAgitService.sendAgit(pushNotificationTemplate, task, taskDetailUrl);
}
private String extractTaskUrl(NotificationType notificationType, Task task, Boolean isManager) {
String taskDetailUrl = "http://localhost:5173/my-request?taskId=" + task.getTaskId();
if (isManager) {
if (notificationType == NotificationType.TASK_REQUESTED) {
taskDetailUrl = "http://localhost:5173/requested?taskId=" + task.getTaskId();
}
else {
taskDetailUrl = "http://localhost:5173/my-task?taskId=" + task.getTaskId();
}
}
return taskDetailUrl;
}
}