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 @@ -4,7 +4,6 @@

public record PushNotificationTemplate(

Long taskId,
String email,
NotificationType notificationType,
String taskName,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
}
}
Expand All @@ -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());
}
}
}
Expand All @@ -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);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@ public ApprovalTaskResponse approvalTaskByReviewer(Long reviewerId, Long taskId,
commandTaskHistoryPort.save(taskHistory);

List<Member> 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));
}
Expand All @@ -70,13 +71,13 @@ public FindApprovalFormResponse findApprovalForm(Long managerId, Long taskId) {
return TaskResponseMapper.toFindApprovalFormResponse(task);
}

private void publishNotification(List<Member> receivers, Task task){
private void publishNotification(List<Member> 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);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand All @@ -59,12 +59,12 @@ private void saveAttachments(List<MultipartFile> files, Task task) {
commandAttachmentPort.saveAll(attachments);
}

private void publishNotification(Task task) {
private void publishNotification(Task task, String taskTitle) {
List<Member> 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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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<Member> 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);
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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);
}
}

Expand All @@ -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
Expand Down Expand Up @@ -140,13 +142,13 @@ private List<Attachment> validateAndGetAttachments(List<Long> attachmentIdsToDel
return attachmentsOfTask;
}

private void publishNotification(Task task, NotificationType notificationType, String message) {
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);
sendNotificationService.sendPushNotification(receiver, receiver.getMemberInfo().getEmail(), notificationType,
task, taskTitle, message, null);
});

sendNotificationService.sendAgitNotification(notificationType, task, message, null);
sendNotificationService.sendAgitNotification(notificationType, task, taskTitle, message, null);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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<Void> saveNotification = CompletableFuture.runAsync(() -> {
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,27 +24,30 @@ 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;
}

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();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
alter table notification
add task_title VARCHAR(20) not null;