diff --git a/src/main/java/clap/server/adapter/outbound/api/dto/PushNotificationTemplate.java b/src/main/java/clap/server/adapter/outbound/api/dto/PushNotificationTemplate.java index 8ed8d8ff..1e15dcfd 100644 --- a/src/main/java/clap/server/adapter/outbound/api/dto/PushNotificationTemplate.java +++ b/src/main/java/clap/server/adapter/outbound/api/dto/PushNotificationTemplate.java @@ -4,7 +4,6 @@ public record PushNotificationTemplate( - Long taskId, String email, NotificationType notificationType, String taskName, diff --git a/src/main/java/clap/server/adapter/outbound/persistense/entity/notification/NotificationEntity.java b/src/main/java/clap/server/adapter/outbound/persistense/entity/notification/NotificationEntity.java index 00e5b3ed..a6c3a8e3 100644 --- a/src/main/java/clap/server/adapter/outbound/persistense/entity/notification/NotificationEntity.java +++ b/src/main/java/clap/server/adapter/outbound/persistense/entity/notification/NotificationEntity.java @@ -37,6 +37,9 @@ public class NotificationEntity extends BaseTimeEntity { @Column(nullable = true) private String message; + @Column(nullable = false) + private String taskTitle; + @Column(nullable = false) private boolean isRead; } 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 945990a3..533efeea 100644 --- a/src/main/java/clap/server/application/service/history/PostCommentService.java +++ b/src/main/java/clap/server/application/service/history/PostCommentService.java @@ -51,10 +51,14 @@ public void save(Long userId, Long taskId, CreateCommentRequest request) { TaskHistory taskHistory = TaskHistory.createTaskHistory(TaskHistoryType.COMMENT, task, null, member, savedComment); commandTaskHistoryPort.save(taskHistory); + String taskTitle = task.getTitle(); + Member receiver; if (member.getMemberInfo().getRole() == MemberRole.ROLE_USER) { - publishNotification(task.getProcessor(), task, comment.getContent(), member.getNickname()); + receiver = task.getProcessor(); + publishNotification(receiver, task, request.content(), member.getNickname(), taskTitle, receiver.getMemberInfo().getEmail()); } else { - publishNotification(task.getRequester(), task, comment.getContent(), task.getProcessor().getNickname()); + receiver = task.getRequester(); + publishNotification(receiver, task, request.content(), receiver.getNickname(), taskTitle, receiver.getMemberInfo().getEmail()); } } } @@ -74,9 +78,11 @@ public void saveCommentAttachment(Long userId, Long taskId, MultipartFile file) commandTaskHistoryPort.save(taskHistory); if (member.getMemberInfo().getRole() == MemberRole.ROLE_USER) { - publishNotification(task.getProcessor(), task, fileName + "(첨부파일)", member.getNickname()); + Member receiver = task.getProcessor(); + publishNotification(receiver, task, fileName + "(첨부파일)", member.getNickname(), task.getTitle(), receiver.getMemberInfo().getEmail()); } else { - publishNotification(task.getRequester(), task, fileName + "(첨부파일)", task.getProcessor().getNickname()); + Member receiver = task.getRequester(); + publishNotification(receiver, task, fileName + "(첨부파일)", task.getProcessor().getNickname(), task.getTitle(), receiver.getMemberInfo().getEmail()); } } } @@ -88,8 +94,8 @@ private String saveAttachment(MultipartFile file, Task task, Comment comment) { return file.getOriginalFilename(); } - private void publishNotification(Member receiver, Task task, String message, String commenterName) { - sendNotificationService.sendPushNotification(receiver, NotificationType.COMMENT, task, message, commenterName); + private void publishNotification(Member receiver, Task task, String message, String commenterName, String taskTitle, String email) { + sendNotificationService.sendPushNotification(receiver, email, NotificationType.COMMENT, task, taskTitle, message, commenterName); } } 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 4c50110c..51f814b0 100644 --- a/src/main/java/clap/server/application/service/task/ApprovalTaskService.java +++ b/src/main/java/clap/server/application/service/task/ApprovalTaskService.java @@ -57,7 +57,8 @@ public ApprovalTaskResponse approvalTaskByReviewer(Long reviewerId, Long taskId, commandTaskHistoryPort.save(taskHistory); List receivers = List.of(reviewer, processor); - publishNotification(receivers, task); + String processorName = task.getProcessor().getNickname(); + publishNotification(receivers, task, task.getTitle(), processorName); return TaskResponseMapper.toApprovalTaskResponse(taskService.upsert(task)); } @@ -70,13 +71,13 @@ public FindApprovalFormResponse findApprovalForm(Long managerId, Long taskId) { return TaskResponseMapper.toFindApprovalFormResponse(task); } - private void publishNotification(List receivers, Task task){ + private void publishNotification(List receivers, Task task, String taskTitle, String processorName){ receivers.forEach(receiver -> { - sendNotificationService.sendPushNotification(receiver, NotificationType.PROCESSOR_ASSIGNED, - task, task.getProcessor().getNickname(), null); + sendNotificationService.sendPushNotification(receiver, receiver.getMemberInfo().getEmail(), NotificationType.PROCESSOR_ASSIGNED, + task, taskTitle, processorName, null); }); sendNotificationService.sendAgitNotification(NotificationType.PROCESSOR_CHANGED, - task, task.getProcessor().getNickname(), null); + task, taskTitle, 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..f3705b34 100644 --- a/src/main/java/clap/server/application/service/task/CreateTaskService.java +++ b/src/main/java/clap/server/application/service/task/CreateTaskService.java @@ -49,7 +49,7 @@ public CreateTaskResponse createTask(Long requesterId, CreateTaskRequest createT if (files != null) { saveAttachments(files, savedTask);} - publishNotification(savedTask); + publishNotification(savedTask, savedTask.getTitle()); return TaskResponseMapper.toCreateTaskResponse(savedTask); } @@ -59,12 +59,12 @@ private void saveAttachments(List files, Task task) { commandAttachmentPort.saveAll(attachments); } - private void publishNotification(Task task) { + private void publishNotification(Task task, String taskTitle) { List reviewers = memberService.findReviewers(); - reviewers.forEach(reviewer -> {sendNotificationService.sendPushNotification(reviewer, NotificationType.TASK_REQUESTED, - task, null, null);}); + reviewers.forEach(reviewer -> {sendNotificationService.sendPushNotification(reviewer, reviewer.getMemberInfo().getNickname(), NotificationType.TASK_REQUESTED, + task, taskTitle, null, null);}); sendNotificationService.sendAgitNotification(NotificationType.TASK_REQUESTED, - task, null, null); + task, taskTitle, null, null); } } \ No newline at end of file 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 2b1ae15e..caffe70b 100644 --- a/src/main/java/clap/server/application/service/task/UpdateTaskBoardService.java +++ b/src/main/java/clap/server/application/service/task/UpdateTaskBoardService.java @@ -181,14 +181,14 @@ public void validateRequest(UpdateTaskOrderRequest request, TaskStatus targetSta } } - private void publishNotification(Task task, NotificationType notificationType, String message) { + 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); + sendNotificationService.sendPushNotification(receiver, receiver.getMemberInfo().getNickname(), notificationType, + task, taskTitle, message, null); }); sendNotificationService.sendAgitNotification(notificationType, - task, message, null); + task, message, taskTitle, 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 c41beab3..79a2ada1 100644 --- a/src/main/java/clap/server/application/service/task/UpdateTaskService.java +++ b/src/main/java/clap/server/application/service/task/UpdateTaskService.java @@ -56,7 +56,6 @@ public class UpdateTaskService implements UpdateTaskUsecase, UpdateTaskStatusUse private final CommandAttachmentPort commandAttachmentPort; private final CommandTaskHistoryPort commandTaskHistoryPort; private final S3UploadPort s3UploadPort; - private final ObjectMapper objectMapper; @Override @Transactional @@ -89,7 +88,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())); + + String taskTitle = task.getTitle(); + publishNotification(updateTask, NotificationType.STATUS_SWITCHED, String.valueOf(updateTask.getTaskStatus()), taskTitle); } } @@ -106,7 +107,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, updateTask.getProcessor().getNickname()); + String taskTitle = task.getTitle(); + publishNotification(updateTask, NotificationType.PROCESSOR_CHANGED, updateTask.getProcessor().getNickname(), taskTitle); } @Transactional @@ -140,13 +142,13 @@ private List validateAndGetAttachments(List attachmentIdsToDel return attachmentsOfTask; } - private void publishNotification(Task task, NotificationType notificationType, String message) { + 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); + sendNotificationService.sendPushNotification(receiver, receiver.getMemberInfo().getEmail(), notificationType, + task, taskTitle, message, null); }); - sendNotificationService.sendAgitNotification(notificationType, task, message, null); + sendNotificationService.sendAgitNotification(notificationType, task, taskTitle, message, null); } } 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 0a0de008..3b57cf9e 100644 --- a/src/main/java/clap/server/application/service/webhook/SendNotificationService.java +++ b/src/main/java/clap/server/application/service/webhook/SendNotificationService.java @@ -25,23 +25,21 @@ public class SendNotificationService { private final CommandNotificationPort commandNotificationPort; @Async("notificationExecutor") - public void sendPushNotification(Member receiver, NotificationType notificationType, - Task task, String message, String commenterName) { - String email = receiver.getMemberInfo().getEmail(); - String taskTitle = task.getTitle(); + 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); + Notification notification = createTaskNotification(task, receiver, notificationType, message, taskTitle); SseRequest sseRequest = new SseRequest( - task.getTitle(), + taskTitle, notificationType, receiver.getMemberId(), message ); PushNotificationTemplate pushNotificationTemplate = new PushNotificationTemplate( - task.getTaskId(), email, notificationType, taskTitle, requesterNickname, message, commenterName + email, notificationType, taskTitle, requesterNickname, message, commenterName ); CompletableFuture saveNotification = CompletableFuture.runAsync(() -> { @@ -71,12 +69,11 @@ public void sendPushNotification(Member receiver, NotificationType notificationT @Async("notificationExecutor") public void sendAgitNotification(NotificationType notificationType, - Task task, String message, String commenterName) { + Task task, String taskTitle, String message, String commenterName) { PushNotificationTemplate pushNotificationTemplate = new PushNotificationTemplate( - task.getTaskId(), null, notificationType, - task.getTitle(), + taskTitle, task.getRequester().getNickname(), message, commenterName diff --git a/src/main/java/clap/server/domain/model/notification/Notification.java b/src/main/java/clap/server/domain/model/notification/Notification.java index 46bd4f26..8a95112f 100644 --- a/src/main/java/clap/server/domain/model/notification/Notification.java +++ b/src/main/java/clap/server/domain/model/notification/Notification.java @@ -24,14 +24,16 @@ public class Notification extends BaseTime { private NotificationType type; private Member receiver; private String message; + private String taskTitle; private boolean isRead; @Builder - public Notification(Task task, NotificationType type, Member receiver, String message) { + public Notification(Task task, NotificationType type, Member receiver, String message, String taskTitle) { this.task = task; this.type = type; this.receiver = receiver; this.message = message; + this.taskTitle = taskTitle; this.isRead = false; } @@ -39,12 +41,13 @@ public void updateNotificationIsRead() { this.isRead = true; } - public static Notification createTaskNotification(Task task, Member reviewer, NotificationType type) { + public static Notification createTaskNotification(Task task, Member reviewer, NotificationType type, String message, String taskTitle) { return Notification.builder() .task(task) .type(type) .receiver(reviewer) - .message(null) + .message(message) + .taskTitle(taskTitle) .build(); } } diff --git a/src/main/resources/db/migration/dev/V20250205278__Insert_Task_Title_Into_Notification.sql b/src/main/resources/db/migration/dev/V20250205278__Insert_Task_Title_Into_Notification.sql new file mode 100644 index 00000000..a5fb6144 --- /dev/null +++ b/src/main/resources/db/migration/dev/V20250205278__Insert_Task_Title_Into_Notification.sql @@ -0,0 +1,2 @@ +alter table notification + add task_title VARCHAR(20) not null; \ No newline at end of file