diff --git a/src/main/java/clap/server/adapter/outbound/api/EmailClient.java b/src/main/java/clap/server/adapter/outbound/api/EmailClient.java index c90b26d5..6ed9f9a4 100644 --- a/src/main/java/clap/server/adapter/outbound/api/EmailClient.java +++ b/src/main/java/clap/server/adapter/outbound/api/EmailClient.java @@ -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); diff --git a/src/main/java/clap/server/adapter/outbound/api/EmailTemplateBuilder.java b/src/main/java/clap/server/adapter/outbound/api/EmailTemplateBuilder.java index be20f02b..4eea20d2 100644 --- a/src/main/java/clap/server/adapter/outbound/api/EmailTemplateBuilder.java +++ b/src/main/java/clap/server/adapter/outbound/api/EmailTemplateBuilder.java @@ -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"; @@ -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()); diff --git a/src/main/java/clap/server/adapter/outbound/api/KakaoWorkBlockBuilder.java b/src/main/java/clap/server/adapter/outbound/api/KakaoWorkBlockBuilder.java index b3fb07f6..f4575a53 100644 --- a/src/main/java/clap/server/adapter/outbound/api/KakaoWorkBlockBuilder.java +++ b/src/main/java/clap/server/adapter/outbound/api/KakaoWorkBlockBuilder.java @@ -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); diff --git a/src/main/java/clap/server/adapter/outbound/api/KakaoWorkClient.java b/src/main/java/clap/server/adapter/outbound/api/KakaoWorkClient.java index 007b9b82..00632f83 100644 --- a/src/main/java/clap/server/adapter/outbound/api/KakaoWorkClient.java +++ b/src/main/java/clap/server/adapter/outbound/api/KakaoWorkClient.java @@ -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(); diff --git a/src/main/java/clap/server/application/port/outbound/webhook/SendKaKaoWorkPort.java b/src/main/java/clap/server/application/port/outbound/webhook/SendKaKaoWorkPort.java index 658002a7..875800ba 100644 --- a/src/main/java/clap/server/application/port/outbound/webhook/SendKaKaoWorkPort.java +++ b/src/main/java/clap/server/application/port/outbound/webhook/SendKaKaoWorkPort.java @@ -4,5 +4,5 @@ public interface SendKaKaoWorkPort { - void sendKakaoWork(PushNotificationTemplate request); + void sendKakaoWork(PushNotificationTemplate request, String taskDetailUrl); } diff --git a/src/main/java/clap/server/application/port/outbound/webhook/SendWebhookEmailPort.java b/src/main/java/clap/server/application/port/outbound/webhook/SendWebhookEmailPort.java index 598926b4..2cd01edc 100644 --- a/src/main/java/clap/server/application/port/outbound/webhook/SendWebhookEmailPort.java +++ b/src/main/java/clap/server/application/port/outbound/webhook/SendWebhookEmailPort.java @@ -4,5 +4,5 @@ public interface SendWebhookEmailPort { - void sendWebhookEmail(PushNotificationTemplate request); + void sendWebhookEmail(PushNotificationTemplate request, String taskDetailUrl); } \ No newline at end of file diff --git a/src/main/java/clap/server/application/service/history/PostCommentService.java b/src/main/java/clap/server/application/service/history/PostCommentService.java index 2e3b6a70..f7b138d1 100644 --- a/src/main/java/clap/server/application/service/history/PostCommentService.java +++ b/src/main/java/clap/server/application/service/history/PostCommentService.java @@ -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); } } diff --git a/src/main/java/clap/server/application/service/task/ApprovalTaskService.java b/src/main/java/clap/server/application/service/task/ApprovalTaskService.java index cd522027..df8e301b 100644 --- a/src/main/java/clap/server/application/service/task/ApprovalTaskService.java +++ b/src/main/java/clap/server/application/service/task/ApprovalTaskService.java @@ -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; @@ -73,10 +74,11 @@ public FindApprovalFormResponse findApprovalForm(Long managerId, Long taskId) { private void publishNotification(List 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); } diff --git a/src/main/java/clap/server/application/service/task/CreateTaskService.java b/src/main/java/clap/server/application/service/task/CreateTaskService.java index b9383966..3601aed0 100644 --- a/src/main/java/clap/server/application/service/task/CreateTaskService.java +++ b/src/main/java/clap/server/application/service/task/CreateTaskService.java @@ -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; @@ -61,8 +62,10 @@ private void saveAttachments(List files, Task task) { private void publishNotification(Task task) { List 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); diff --git a/src/main/java/clap/server/application/service/task/UpdateTaskBoardService.java b/src/main/java/clap/server/application/service/task/UpdateTaskBoardService.java index dee1a5cd..e88f1e05 100644 --- a/src/main/java/clap/server/application/service/task/UpdateTaskBoardService.java +++ b/src/main/java/clap/server/application/service/task/UpdateTaskBoardService.java @@ -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; @@ -184,7 +185,8 @@ public void validateRequest(UpdateTaskOrderRequest request, TaskStatus targetSta private void publishNotification(Task task, NotificationType notificationType, String message, String taskTitle) { List 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); diff --git a/src/main/java/clap/server/application/service/task/UpdateTaskService.java b/src/main/java/clap/server/application/service/task/UpdateTaskService.java index 7190ecc2..358ed8cf 100644 --- a/src/main/java/clap/server/application/service/task/UpdateTaskService.java +++ b/src/main/java/clap/server/application/service/task/UpdateTaskService.java @@ -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; @@ -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 receivers = List.of(task.getRequester(), task.getProcessor()); + publishNotification(receivers, updateTask, NotificationType.STATUS_SWITCHED, String.valueOf(updateTask.getTaskStatus())); } } @@ -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 receivers = List.of(updateTask.getRequester(), updateTask.getProcessor()); + publishNotification(receivers, updateTask, NotificationType.PROCESSOR_CHANGED, processor.getNickname()); } @Transactional @@ -135,13 +139,13 @@ private List validateAndGetAttachments(List attachmentIdsToDel return attachmentsOfTask; } - private void publishNotification(Task task, NotificationType notificationType, String message) { - List receivers = List.of(task.getRequester(), task.getProcessor()); + private void publishNotification(List 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); } } diff --git a/src/main/java/clap/server/application/service/webhook/NotificationSender.java b/src/main/java/clap/server/application/service/webhook/NotificationSender.java index 0591d323..04f0cd29 100644 --- a/src/main/java/clap/server/application/service/webhook/NotificationSender.java +++ b/src/main/java/clap/server/application/service/webhook/NotificationSender.java @@ -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); } \ No newline at end of file diff --git a/src/main/java/clap/server/application/service/webhook/SendKaKaoWorkService.java b/src/main/java/clap/server/application/service/webhook/SendKaKaoWorkService.java index a341c1d0..81eefede 100644 --- a/src/main/java/clap/server/application/service/webhook/SendKaKaoWorkService.java +++ b/src/main/java/clap/server/application/service/webhook/SendKaKaoWorkService.java @@ -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); } } diff --git a/src/main/java/clap/server/application/service/webhook/SendNotificationService.java b/src/main/java/clap/server/application/service/webhook/SendNotificationService.java index e28203fe..385c9bce 100644 --- a/src/main/java/clap/server/application/service/webhook/SendNotificationService.java +++ b/src/main/java/clap/server/application/service/webhook/SendNotificationService.java @@ -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 @@ -50,27 +46,49 @@ public void sendPushNotification(Member receiver, NotificationType notificationT commandNotificationPort.save(notification); }); - CompletableFuture sendSseFuture = CompletableFuture.runAsync(() -> { - sendSsePort.send(sseRequest); - }); - CompletableFuture sendEmailFuture = CompletableFuture.runAsync(() -> { if (receiver.getEmailNotificationEnabled()) { - sendWebhookEmailService.send(pushNotificationTemplate); + sendWebhookEmailService.send(pushNotificationTemplate, taskDetailUrl); } }); CompletableFuture sendKakaoWorkFuture = CompletableFuture.runAsync(() -> { if (receiver.getKakaoworkNotificationEnabled()) { - sendKaKaoWorkService.send(pushNotificationTemplate); + sendKaKaoWorkService.send(pushNotificationTemplate, taskDetailUrl); } }); - CompletableFuture allOf = CompletableFuture.allOf(saveNotification, sendSseFuture, + //Todo : SSE 구현시 추가 + //SseRequest sseRequest = new SseRequest( + // taskTitle, + // notificationType, + // receiver.getMemberId(), + // message + //); + + //Todo : SSE 구현시 추가 + //CompletableFuture sendSseFuture = CompletableFuture.runAsync(() -> { + // sendSsePort.send(sseRequest); + //}); + + CompletableFuture 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) { diff --git a/src/main/java/clap/server/application/service/webhook/SendWebhookEmailService.java b/src/main/java/clap/server/application/service/webhook/SendWebhookEmailService.java index ee7fd241..4d5964b1 100644 --- a/src/main/java/clap/server/application/service/webhook/SendWebhookEmailService.java +++ b/src/main/java/clap/server/application/service/webhook/SendWebhookEmailService.java @@ -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); } }