-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathSendNotificationService.java
More file actions
84 lines (69 loc) · 3.47 KB
/
SendNotificationService.java
File metadata and controls
84 lines (69 loc) · 3.47 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
package clap.server.application.service.webhook;
import clap.server.adapter.inbound.web.dto.notification.request.SseRequest;
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 SendEmailService sendEmailService;
private final SendKaKaoWorkService sendKaKaoWorkService;
private final CommandNotificationPort commandNotificationPort;
@Async("notificationExecutor")
public void sendPushNotification(Member receiver, String email, NotificationType notificationType,
Task task, String taskTitle, String message, String commenterName) {
String requesterNickname = task.getRequester().getNickname();
Notification notification = createTaskNotification(task, receiver, notificationType, message, taskTitle);
SseRequest sseRequest = new SseRequest(
taskTitle,
notificationType,
receiver.getMemberId(),
message
);
PushNotificationTemplate pushNotificationTemplate = new PushNotificationTemplate(
email, notificationType, taskTitle, requesterNickname, message, commenterName
);
CompletableFuture<Void> saveNotification = CompletableFuture.runAsync(() -> {
commandNotificationPort.save(notification);
});
CompletableFuture<Void> sendSseFuture = CompletableFuture.runAsync(() -> {
sendSseService.send(sseRequest);
});
CompletableFuture<Void> sendEmailFuture = CompletableFuture.runAsync(() -> {
if (receiver.getEmailNotificationEnabled()) {
sendEmailService.sendEmail(pushNotificationTemplate);
}
});
CompletableFuture<Void> sendKakaoWorkFuture = CompletableFuture.runAsync(() -> {
if (receiver.getKakaoworkNotificationEnabled()) {
sendKaKaoWorkService.sendKaKaoWork(pushNotificationTemplate);
}
});
CompletableFuture<Void> allOf = CompletableFuture.allOf(saveNotification, sendSseFuture,
sendEmailFuture, sendKakaoWorkFuture);
allOf.join();
}
@Async("notificationExecutor")
public void sendAgitNotification(NotificationType notificationType,
Task task, String taskTitle, String message, String commenterName) {
PushNotificationTemplate pushNotificationTemplate = new PushNotificationTemplate(
null,
notificationType,
taskTitle,
task.getRequester().getNickname(),
message,
commenterName
);
sendAgitService.sendAgit(pushNotificationTemplate, task);
}
}