Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@ public class EmailClient implements SendEmailPort, SendWebhookEmailPort {
private final JavaMailSender mailSender;

@Override
public void sendWebhookEmail(PushNotificationTemplate request) {
public void sendWebhookEmail(PushNotificationTemplate request, String taskDetailUrl) {
try {
MimeMessage mimeMessage = mailSender.createMimeMessage();
MimeMessageHelper helper = new MimeMessageHelper(mimeMessage, true, "UTF-8");

EmailTemplate template = emailTemplateBuilder.createWebhookTemplate(request);
EmailTemplate template = emailTemplateBuilder.createWebhookTemplate(request, taskDetailUrl);
helper.setTo(template.email());
helper.setSubject(template.subject());
helper.setText(template.body(), true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,10 @@ public class EmailTemplateBuilder {

private final SpringTemplateEngine templateEngine;

public EmailTemplate createWebhookTemplate(PushNotificationTemplate request) {
public EmailTemplate createWebhookTemplate(PushNotificationTemplate request, String taskDetailUrl) {
Context context = new Context();
String templateName = "";
String subject = "";
String taskDetailUrl = "https://www.naver.com"; //ToDo task 상세 조회페이지 url 추가
switch (request.notificationType()) {
case TASK_REQUESTED:
templateName = "task-request";
Expand Down Expand Up @@ -48,6 +47,7 @@ public EmailTemplate createWebhookTemplate(PushNotificationTemplate request) {
context.setVariable("title", request.taskName());
break;
case COMMENT:
templateName = "comment";
subject = "[TaskFlow 알림] 댓글이 작성되었습니다.";
context.setVariable("taskDetailUrl", taskDetailUrl);
context.setVariable("comment", request.message());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@ public class KakaoWorkBlockBuilder {

private final ObjectMapper objectMapper;

public String makeObjectBlock(PushNotificationTemplate request){
String taskDetailUrl = "https://www.naver.com";
public String makeObjectBlock(PushNotificationTemplate request, String taskDetailUrl){
return switch (request.notificationType()) {
case TASK_REQUESTED -> makeTaskRequestBlock(request, taskDetailUrl);
case STATUS_SWITCHED -> makeTaskStatusBlock(request, taskDetailUrl);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@ public class KakaoWorkClient implements SendKaKaoWorkPort {
private final KakaoWorkBlockBuilder kakaoWorkBlockBuilder;

@Override
public void sendKakaoWork(PushNotificationTemplate request) {
public void sendKakaoWork(PushNotificationTemplate request, String taskDetailUrl) {
RestTemplate restTemplate = new RestTemplate();

// Payload 생성
String payload = kakaoWorkBlockBuilder.makeObjectBlock(request);
String payload = kakaoWorkBlockBuilder.makeObjectBlock(request, taskDetailUrl);

// HTTP 요청 헤더 설정
HttpHeaders headers = new HttpHeaders();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@

public interface SendKaKaoWorkPort {

void sendKakaoWork(PushNotificationTemplate request);
void sendKakaoWork(PushNotificationTemplate request, String taskDetailUrl);
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@

public interface SendWebhookEmailPort {

void sendWebhookEmail(PushNotificationTemplate request);
void sendWebhookEmail(PushNotificationTemplate request, String taskDetailUrl);
}
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ private String saveAttachment(MultipartFile file, Task task, Comment comment) {
}

private void publishNotification(Member receiver, Task task, String message, String commenterName) {
sendNotificationService.sendPushNotification(receiver, NotificationType.COMMENT, task, message, commenterName);
boolean isManager = receiver.getMemberInfo().getRole() == MemberRole.ROLE_MANAGER;
sendNotificationService.sendPushNotification(receiver, NotificationType.COMMENT, task, message, commenterName, isManager);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import clap.server.adapter.inbound.web.dto.task.request.ApprovalTaskRequest;
import clap.server.adapter.inbound.web.dto.task.response.ApprovalTaskResponse;
import clap.server.adapter.inbound.web.dto.task.response.FindApprovalFormResponse;
import clap.server.adapter.outbound.persistense.entity.member.constant.MemberRole;
import clap.server.adapter.outbound.persistense.entity.notification.constant.NotificationType;
import clap.server.adapter.outbound.persistense.entity.task.constant.TaskHistoryType;
import clap.server.application.mapper.TaskResponseMapper;
Expand Down Expand Up @@ -73,10 +74,11 @@ public FindApprovalFormResponse findApprovalForm(Long managerId, Long taskId) {

private void publishNotification(List<Member> receivers, Task task, String processorName){
receivers.forEach(receiver -> {
boolean isManager = receiver.getMemberInfo().getRole() == MemberRole.ROLE_MANAGER;
sendNotificationService.sendPushNotification(receiver, NotificationType.PROCESSOR_ASSIGNED,
task, processorName, null);
task, processorName, null, isManager);
});
sendNotificationService.sendAgitNotification(NotificationType.PROCESSOR_CHANGED,
sendNotificationService.sendAgitNotification(NotificationType.PROCESSOR_ASSIGNED,
task, processorName, null);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import clap.server.adapter.inbound.web.dto.task.request.CreateTaskRequest;
import clap.server.adapter.inbound.web.dto.task.response.CreateTaskResponse;

import clap.server.adapter.outbound.persistense.entity.member.constant.MemberRole;
import clap.server.adapter.outbound.persistense.entity.notification.constant.NotificationType;
import clap.server.application.mapper.AttachmentMapper;
import clap.server.application.mapper.TaskResponseMapper;
Expand Down Expand Up @@ -61,8 +62,10 @@ private void saveAttachments(List<MultipartFile> files, Task task) {

private void publishNotification(Task task) {
List<Member> reviewers = memberService.findReviewers();
reviewers.forEach(reviewer -> {sendNotificationService.sendPushNotification(reviewer, NotificationType.TASK_REQUESTED,
task, null, null);});
reviewers.forEach(reviewer -> {
boolean isManager = reviewer.getMemberInfo().getRole() == MemberRole.ROLE_MANAGER;
sendNotificationService.sendPushNotification(reviewer, NotificationType.TASK_REQUESTED,
task, null, null, isManager);});

sendNotificationService.sendAgitNotification(NotificationType.TASK_REQUESTED,
task, null, null);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package clap.server.application.service.task;

import clap.server.adapter.inbound.web.dto.task.request.UpdateTaskOrderRequest;
import clap.server.adapter.outbound.persistense.entity.member.constant.MemberRole;
import clap.server.adapter.outbound.persistense.entity.notification.constant.NotificationType;
import clap.server.adapter.outbound.persistense.entity.task.constant.TaskHistoryType;
import clap.server.adapter.outbound.persistense.entity.task.constant.TaskStatus;
Expand Down Expand Up @@ -184,7 +185,8 @@ public void validateRequest(UpdateTaskOrderRequest request, TaskStatus targetSta
private void publishNotification(Task task, NotificationType notificationType, String message, String taskTitle) {
List<Member> receivers = List.of(task.getRequester(), task.getProcessor());
receivers.forEach(receiver -> {
sendNotificationService.sendPushNotification(receiver, notificationType, task, message, null);
boolean isManager = receiver.getMemberInfo().getRole() == MemberRole.ROLE_MANAGER;
sendNotificationService.sendPushNotification(receiver, notificationType, task, message, null, isManager);
});
sendNotificationService.sendAgitNotification(notificationType,
task, message, null);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import clap.server.adapter.inbound.web.dto.task.request.UpdateTaskLabelRequest;
import clap.server.adapter.inbound.web.dto.task.request.UpdateTaskProcessorRequest;
import clap.server.adapter.inbound.web.dto.task.request.UpdateTaskRequest;
import clap.server.adapter.outbound.persistense.entity.member.constant.MemberRole;
import clap.server.adapter.outbound.persistense.entity.notification.constant.NotificationType;
import clap.server.adapter.outbound.persistense.entity.task.constant.TaskHistoryType;
import clap.server.adapter.outbound.persistense.entity.task.constant.TaskStatus;
Expand Down Expand Up @@ -83,7 +84,9 @@ public void updateTaskStatus(Long memberId, Long taskId, TaskStatus taskStatus)
Task updateTask = taskService.upsert(task);
TaskHistory taskHistory = TaskHistory.createTaskHistory(TaskHistoryType.STATUS_SWITCHED, task, taskStatus.getDescription(), null,null);
commandTaskHistoryPort.save(taskHistory);
publishNotification(updateTask, NotificationType.STATUS_SWITCHED, String.valueOf(updateTask.getTaskStatus()));

List<Member> receivers = List.of(task.getRequester(), task.getProcessor());
publishNotification(receivers, updateTask, NotificationType.STATUS_SWITCHED, String.valueOf(updateTask.getTaskStatus()));
}
}

Expand All @@ -101,7 +104,8 @@ public void updateTaskProcessor(Long taskId, Long userId, UpdateTaskProcessorReq
TaskHistory taskHistory = TaskHistory.createTaskHistory(TaskHistoryType.PROCESSOR_CHANGED, task, null, processor,null);
commandTaskHistoryPort.save(taskHistory);

publishNotification(updateTask, NotificationType.PROCESSOR_CHANGED, processor.getNickname());
List<Member> receivers = List.of(updateTask.getRequester(), updateTask.getProcessor());
publishNotification(receivers, updateTask, NotificationType.PROCESSOR_CHANGED, processor.getNickname());
}

@Transactional
Expand Down Expand Up @@ -135,13 +139,13 @@ private List<Attachment> validateAndGetAttachments(List<Long> attachmentIdsToDel
return attachmentsOfTask;
}

private void publishNotification(Task task, NotificationType notificationType, String message) {
List<Member> receivers = List.of(task.getRequester(), task.getProcessor());
private void publishNotification(List<Member> receivers, Task task, NotificationType notificationType, String message) {
receivers.forEach(receiver -> {
boolean isManager = receiver.getMemberInfo().getRole() == MemberRole.ROLE_MANAGER;
sendNotificationService.sendPushNotification(receiver, notificationType,
task, message, null);
task, message, null, isManager);
});

sendNotificationService.sendAgitNotification(notificationType, task, message, null);
sendNotificationService.sendAgitNotification(notificationType, task, message, null);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
import clap.server.adapter.outbound.api.dto.PushNotificationTemplate;

public interface NotificationSender {
void send(PushNotificationTemplate template);
void send(PushNotificationTemplate template, String taskDetailUrl);
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public class SendKaKaoWorkService implements NotificationSender {

private final SendKaKaoWorkPort sendKaKaoWorkPort;

public void send(PushNotificationTemplate request) {
sendKaKaoWorkPort.sendKakaoWork(request);
public void send(PushNotificationTemplate request, String taskDetailUrl) {
sendKaKaoWorkPort.sendKakaoWork(request, taskDetailUrl);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,19 +28,15 @@ public class SendNotificationService {

@Async("notificationExecutor")
public void sendPushNotification(Member receiver, NotificationType notificationType,
Task task, String message, String commenterName) {
Task task, String message, String commenterName, Boolean isManager) {

String email = receiver.getMemberInfo().getEmail();
String taskTitle = task.getTitle();
String requesterNickname = task.getRequester().getNickname();

Notification notification = createTaskNotification(task, receiver, notificationType, message, taskTitle);
String taskDetailUrl = extractTaskUrl(notificationType, task, isManager);

SseRequest sseRequest = new SseRequest(
taskTitle,
notificationType,
receiver.getMemberId(),
message
);
Notification notification = createTaskNotification(task, receiver, notificationType, message, taskTitle);

PushNotificationTemplate pushNotificationTemplate = new PushNotificationTemplate(
email, notificationType, taskTitle, requesterNickname, message, commenterName
Expand All @@ -50,27 +46,49 @@ public void sendPushNotification(Member receiver, NotificationType notificationT
commandNotificationPort.save(notification);
});

CompletableFuture<Void> sendSseFuture = CompletableFuture.runAsync(() -> {
sendSsePort.send(sseRequest);
});

CompletableFuture<Void> sendEmailFuture = CompletableFuture.runAsync(() -> {
if (receiver.getEmailNotificationEnabled()) {
sendWebhookEmailService.send(pushNotificationTemplate);
sendWebhookEmailService.send(pushNotificationTemplate, taskDetailUrl);
}
});

CompletableFuture<Void> sendKakaoWorkFuture = CompletableFuture.runAsync(() -> {
if (receiver.getKakaoworkNotificationEnabled()) {
sendKaKaoWorkService.send(pushNotificationTemplate);
sendKaKaoWorkService.send(pushNotificationTemplate, taskDetailUrl);
}
});

CompletableFuture<Void> allOf = CompletableFuture.allOf(saveNotification, sendSseFuture,
//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();
}

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;
}

@Async("notificationExecutor")
public void sendAgitNotification(NotificationType notificationType,
Task task, String message, String commenterName) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public class SendWebhookEmailService implements NotificationSender {

private final SendWebhookEmailPort sendWebhookEmailPort;

public void send(PushNotificationTemplate request) {
sendWebhookEmailPort.sendWebhookEmail(request);
public void send(PushNotificationTemplate request, String taskDetailUrl) {
sendWebhookEmailPort.sendWebhookEmail(request, taskDetailUrl);
}
}