Skip to content

Commit 20577e8

Browse files
committed
CLAP-370 Fix : 작업 종료 알림 템플릿 생성 및 수정
1 parent d3649f4 commit 20577e8

File tree

11 files changed

+201
-20
lines changed

11 files changed

+201
-20
lines changed

src/main/java/clap/server/adapter/outbound/api/data/PushNotificationTemplate.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ public record PushNotificationTemplate(
99
String taskName,
1010
String senderName,
1111
String message,
12-
String commenterName
12+
String commenterName,
13+
String reason
1314
) {
1415
}

src/main/java/clap/server/adapter/outbound/api/email/EmailTemplateBuilder.java

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,20 @@ public EmailTemplate createWebhookTemplate(PushNotificationTemplate request, Str
3030
context.setVariable("title", request.taskName());
3131
break;
3232
case STATUS_SWITCHED:
33-
templateName = "status-switched";
34-
subject = "[TaskFlow] "+ request.taskName()+ " 작업의 상태가 " + request.message() + "으로 변경되었습니다.";
35-
context.setVariable("taskDetailUrl", taskDetailUrl);
36-
context.setVariable("receiverName", request.senderName());
37-
context.setVariable("title", request.taskName());
38-
context.setVariable("status", request.message());
33+
if (request.message().equals("TERMINATED")) {
34+
templateName = "task-terminated";
35+
subject = "[TaskFlow] " + request.taskName() + " 작업이 종료되었습니다.";
36+
context.setVariable("taskDetailUrl", taskDetailUrl);
37+
context.setVariable("reason", request.reason());
38+
context.setVariable("title", request.taskName());
39+
} else {
40+
templateName = "status-switched";
41+
subject = "[TaskFlow] "+ request.taskName()+ " 작업의 상태가 " + request.message() + "으로 변경되었습니다.";
42+
context.setVariable("taskDetailUrl", taskDetailUrl);
43+
context.setVariable("receiverName", request.senderName());
44+
context.setVariable("title", request.taskName());
45+
context.setVariable("status", request.message());
46+
}
3947
break;
4048
case PROCESSOR_CHANGED:
4149
templateName = "processor-changed";

src/main/java/clap/server/adapter/outbound/api/kakaoWork/KakaoWorkBlockBuilder.java

Lines changed: 72 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,10 @@ public class KakaoWorkBlockBuilder {
1717
public String makeObjectBlock(PushNotificationTemplate request, String taskDetailUrl){
1818
return switch (request.notificationType()) {
1919
case TASK_REQUESTED -> makeTaskRequestBlock(request, taskDetailUrl);
20-
case STATUS_SWITCHED -> makeTaskStatusBlock(request, taskDetailUrl);
20+
case STATUS_SWITCHED -> switch (request.message()) { // getStatusChangeType() 메서드로 추가 분기
21+
case "TERMINATED" -> makeTerminatedStatusBlock(request, taskDetailUrl);
22+
default -> makeTaskStatusBlock(request, taskDetailUrl);
23+
};
2124
case PROCESSOR_CHANGED -> makeProcessorChangeBlock(request, taskDetailUrl);
2225
case PROCESSOR_ASSIGNED -> makeNewProcessorBlock(request, taskDetailUrl);
2326
case COMMENT -> makeCommentBlock(request, taskDetailUrl);
@@ -366,4 +369,72 @@ private String makeTaskStatusBlock(PushNotificationTemplate request, String task
366369

367370
return payload;
368371
}
372+
373+
private String makeTerminatedStatusBlock(PushNotificationTemplate request, String taskDetailUrl) {
374+
Object[] blocks = new Object[]{
375+
Map.of(
376+
"type", "header",
377+
"text", "TaskFlow 알림 서비스",
378+
"style", "blue"
379+
),
380+
Map.of(
381+
"type", "text",
382+
"text", "TaskFlow 작업 종료 알림",
383+
"inlines", new Object[]{
384+
Map.of(
385+
"type", "styled",
386+
"text", "TaskFlow 작업 종료 알림",
387+
"bold", true
388+
)
389+
}
390+
),
391+
Map.of(
392+
"type", "text",
393+
"text", "TaskFlow 작업 종료 알림",
394+
"inlines", new Object[]{
395+
Map.of(
396+
"type", "styled",
397+
"text", " - Task Title : " + request.taskName(),
398+
"bold", false
399+
)
400+
}
401+
),
402+
Map.of(
403+
"type", "text",
404+
"text", "TaskFlow 작업 종료 알림",
405+
"inlines", new Object[]{
406+
Map.of(
407+
"type", "styled",
408+
"text", " - 거절 사유 : " + request.reason(),
409+
"bold", false
410+
)
411+
}
412+
),
413+
Map.of(
414+
"type", "button",
415+
"text", "확인하기",
416+
"style", "default",
417+
"action", Map.of(
418+
"type", "open_system_browser",
419+
"name", "button1",
420+
"value", taskDetailUrl
421+
)
422+
)
423+
};
424+
425+
String payload;
426+
try {
427+
payload = "{" +
428+
"\"email\":\"" + request.email() + "\"," +
429+
"\"text\":\"작업 종료 알림\"," +
430+
"\"blocks\":" + objectMapper.writeValueAsString(blocks) +
431+
"}";
432+
} catch (JsonProcessingException e) {
433+
throw new RuntimeException(e);
434+
}
435+
436+
return payload;
437+
}
438+
439+
369440
}

src/main/java/clap/server/application/service/history/PostCommentService.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,6 @@ private String saveAttachment(MultipartFile file, Task task, Comment comment) {
9797

9898
private void publishNotification(Member receiver, Task task, String message, String commenterName) {
9999
boolean isManager = receiver.getMemberInfo().getRole() == MemberRole.ROLE_MANAGER;
100-
sendNotificationService.sendPushNotification(receiver, NotificationType.COMMENT, task, message, commenterName, isManager);
100+
sendNotificationService.sendPushNotification(receiver, NotificationType.COMMENT, task, message, null, commenterName, isManager);
101101
}
102102
}

src/main/java/clap/server/application/service/task/ApprovalTaskService.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ private void publishNotification(List<Member> receivers, Task task, String proce
7575
receivers.forEach(receiver -> {
7676
boolean isManager = receiver.getMemberInfo().getRole() == MemberRole.ROLE_MANAGER;
7777
sendNotificationService.sendPushNotification(receiver, NotificationType.PROCESSOR_ASSIGNED,
78-
task, processorName, null, isManager);
78+
task, processorName, null, null, isManager);
7979
});
8080
sendNotificationService.sendAgitNotification(NotificationType.PROCESSOR_ASSIGNED,
8181
task, processorName, null);

src/main/java/clap/server/application/service/task/CreateTaskService.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ private void publishNotification(Task task) {
7070
reviewers.forEach(reviewer -> {
7171
boolean isManager = reviewer.getMemberInfo().getRole() == MemberRole.ROLE_MANAGER;
7272
sendNotificationService.sendPushNotification(reviewer, NotificationType.TASK_REQUESTED,
73-
task, null, null, isManager);
73+
task, null, null, null, isManager);
7474
});
7575

7676
sendNotificationService.sendAgitNotification(NotificationType.TASK_REQUESTED,

src/main/java/clap/server/application/service/task/TerminateTaskService.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,30 @@
11
package clap.server.application.service.task;
22

3+
import clap.server.adapter.outbound.persistense.entity.member.constant.MemberRole;
4+
import clap.server.adapter.outbound.persistense.entity.notification.constant.NotificationType;
35
import clap.server.adapter.outbound.persistense.entity.task.constant.TaskHistoryType;
46
import clap.server.application.port.inbound.domain.MemberService;
57
import clap.server.application.port.inbound.domain.TaskService;
68
import clap.server.application.port.inbound.task.TerminateTaskUsecase;
79
import clap.server.application.port.outbound.taskhistory.CommandTaskHistoryPort;
10+
import clap.server.application.service.webhook.SendNotificationService;
811
import clap.server.common.annotation.architecture.ApplicationService;
12+
import clap.server.domain.model.member.Member;
913
import clap.server.domain.model.task.Task;
1014
import clap.server.domain.model.task.TaskHistory;
1115
import lombok.RequiredArgsConstructor;
1216
import org.springframework.transaction.annotation.Transactional;
1317

18+
import java.util.List;
19+
1420
@ApplicationService
1521
@RequiredArgsConstructor
1622
@Transactional
1723
public class TerminateTaskService implements TerminateTaskUsecase {
1824
private final MemberService memberService;
1925
private final TaskService taskService;
2026
private final CommandTaskHistoryPort commandTaskHistoryPort;
27+
private final SendNotificationService sendNotificationService;
2128

2229
@Override
2330
public void terminateTask(Long memberId, Long taskId, String reason) {
@@ -28,5 +35,12 @@ public void terminateTask(Long memberId, Long taskId, String reason) {
2835

2936
TaskHistory taskHistory = TaskHistory.createTaskHistory(TaskHistoryType.TASK_TERMINATED, task, reason, null, null);
3037
commandTaskHistoryPort.save(taskHistory);
38+
39+
publishNotification(task.getRequester(), task, String.valueOf(task.getTaskStatus()), reason);
40+
41+
}
42+
43+
private void publishNotification(Member receiver, Task task, String message, String reason) {
44+
sendNotificationService.sendPushNotification(receiver, NotificationType.STATUS_SWITCHED, task, message, reason, null, false);
3145
}
3246
}

src/main/java/clap/server/application/service/task/UpdateTaskBoardService.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ public void updateTaskOrderAndStatus(Long processorId, UpdateTaskOrderRequest re
159159

160160
TaskHistory taskHistory = TaskHistory.createTaskHistory(TaskHistoryType.STATUS_SWITCHED, updatedTask, targetStatus.getDescription(), null,null);
161161
commandTaskHistoryPort.save(taskHistory);
162-
publishNotification(targetTask, NotificationType.STATUS_SWITCHED, String.valueOf(updatedTask.getTaskStatus()));
162+
publishNotification(targetTask);
163163
}
164164

165165
/**
@@ -181,14 +181,14 @@ public void validateRequest(UpdateTaskOrderRequest request, TaskStatus targetSta
181181
}
182182
}
183183

184-
private void publishNotification(Task task, NotificationType notificationType, String message) {
184+
private void publishNotification(Task task) {
185185
List<Member> receivers = List.of(task.getRequester(), task.getProcessor());
186186
receivers.forEach(receiver -> {
187187
boolean isManager = receiver.getMemberInfo().getRole() == MemberRole.ROLE_MANAGER;
188-
sendNotificationService.sendPushNotification(receiver, notificationType, task, message, null, isManager);
188+
sendNotificationService.sendPushNotification(receiver, NotificationType.STATUS_SWITCHED, task, String.valueOf(task.getTaskStatus()), null, null, isManager);
189189
});
190-
sendNotificationService.sendAgitNotification(notificationType,
191-
task, message, null);
190+
sendNotificationService.sendAgitNotification(NotificationType.STATUS_SWITCHED,
191+
task, String.valueOf(task.getTaskStatus()), null);
192192
}
193193

194194
}

src/main/java/clap/server/application/service/task/UpdateTaskService.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ private void publishNotification(List<Member> receivers, Task task, Notification
151151
receivers.forEach(receiver -> {
152152
boolean isManager = receiver.getMemberInfo().getRole() == MemberRole.ROLE_MANAGER;
153153
sendNotificationService.sendPushNotification(receiver, notificationType,
154-
task, message, null, isManager);
154+
task, message, null, null, isManager);
155155
});
156156

157157
sendNotificationService.sendAgitNotification(notificationType, task, message, null);

src/main/java/clap/server/application/service/webhook/SendNotificationService.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public class SendNotificationService {
3737

3838
@Async("notificationExecutor")
3939
public void sendPushNotification(Member receiver, NotificationType notificationType,
40-
Task task, String message, String commenterName, Boolean isManager) {
40+
Task task, String message, String reason, String commenterName, Boolean isManager) {
4141

4242
String email = receiver.getMemberInfo().getEmail();
4343
String taskTitle = task.getTitle();
@@ -48,7 +48,7 @@ public void sendPushNotification(Member receiver, NotificationType notificationT
4848
Notification notification = createTaskNotification(task, receiver, notificationType, message, taskTitle);
4949

5050
PushNotificationTemplate pushNotificationTemplate = new PushNotificationTemplate(
51-
email, notificationType, taskTitle, requesterNickname, message, commenterName
51+
email, notificationType, taskTitle, requesterNickname, message, commenterName, reason
5252
);
5353

5454
CompletableFuture<Void> saveNotification = CompletableFuture.runAsync(() -> {
@@ -95,7 +95,8 @@ public void sendAgitNotification(NotificationType notificationType,
9595
task.getTitle(),
9696
task.getRequester().getNickname(),
9797
message,
98-
commenterName
98+
commenterName,
99+
null
99100
);
100101

101102
String taskDetailUrl = extractTaskUrl(notificationType, task, true);

0 commit comments

Comments
 (0)