Skip to content

Commit a2b2daa

Browse files
authored
Merge pull request #483 from TaskFlow-CLAP/CLAP-370
CLAP-370 작업 취소시 알림에서 발생하는 오류 해결
2 parents fd4dc8f + 20577e8 commit a2b2daa

File tree

12 files changed

+214
-33
lines changed

12 files changed

+214
-33
lines changed

src/main/java/clap/server/adapter/outbound/api/agit/AgitTemplateBuilder.java

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -42,19 +42,19 @@ public String createPayLoad(PushNotificationTemplate request, Task task, String
4242

4343
public String createMessage(PushNotificationTemplate request, String taskDetailUrl) {
4444

45-
return switch (request.notificationType()) {
46-
case TASK_REQUESTED -> "📌 *새 작업 요청:* `" + request.taskName() + "`\\n"
47-
+ "\\t\\t*•요청자: " + request.senderName() + "*\\n"
48-
+ "[확인하러 가기](" + taskDetailUrl + ")";
49-
case STATUS_SWITCHED -> "⚙️ *작업 상태 변경:* `" + request.taskName() + "\\n"
50-
+ "\\t\\t*•작업 상태: " + request.message() + "*\\n"
51-
+ "[확인하러 가기](" + taskDetailUrl + ")";
52-
case PROCESSOR_CHANGED -> "🔄 *담당자 변경:* `" + request.taskName() + "\\n"
53-
+ "\\t\\t*•새 담당자: " + request.message() + "*\\n"
54-
+ "[확인하러 가기](" + taskDetailUrl + ")";
55-
case PROCESSOR_ASSIGNED -> "👤 *작업 담당자 배정:* `" + request.taskName() + "\\n"
56-
+ "\\t\\t*•담당자: " + request.message() + "*\\n"
57-
+ "[확인하러 가기](" + taskDetailUrl + ")";
45+
return switch (request.notificationType()) {
46+
case TASK_REQUESTED -> "📌 *새 작업이 요청되었습니다.*\\n"
47+
+ "\\t\\t*• 🔖 작업명:* " + "*" + request.taskName() + "*" + "\\n"
48+
+ "\\t\\t*• 🙋 요청자:* " + "*" + request.senderName() + "*" + "\\n\\n"
49+
+ "\\t[자세히 보기](" + taskDetailUrl + ")";
50+
51+
case STATUS_SWITCHED -> "작업 상태가 " + "*" + request.message() + "*" + "으로 변경되었습니다.";
52+
53+
case PROCESSOR_CHANGED -> "담당자가 " + "*" + request.message() + "*" + "으로 변경되었습니다.";
54+
55+
case PROCESSOR_ASSIGNED -> "작업이 *승인*되었습니다.*\n"
56+
+ "\\t\\t*• 👤 담당자:* " + "*" + request.message() + "*";
57+
5858
default -> null;
5959
};
6060
}

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
@@ -149,7 +149,7 @@ private void publishNotification(List<Member> receivers, Task task, Notification
149149
receivers.forEach(receiver -> {
150150
boolean isManager = receiver.getMemberInfo().getRole() == MemberRole.ROLE_MANAGER;
151151
sendNotificationService.sendPushNotification(receiver, notificationType,
152-
task, message, null, isManager);
152+
task, message, null, null, isManager);
153153
});
154154

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

0 commit comments

Comments
 (0)