Skip to content

Commit 317e865

Browse files
authored
Merge pull request #278 from TaskFlow-CLAP/CLAP-247
CLAP-247 Notification Service 리팩토링 작업
2 parents 9cf0e21 + 5e92a2c commit 317e865

24 files changed

+123
-199
lines changed
Lines changed: 29 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package clap.server.adapter.outbound.api;
22

3-
import clap.server.adapter.outbound.api.dto.SendWebhookRequest;
4-
import clap.server.adapter.outbound.persistense.entity.notification.constant.NotificationType;
3+
import clap.server.adapter.outbound.api.dto.PushNotificationTemplate;
54
import clap.server.application.port.outbound.webhook.SendAgitPort;
65
import clap.server.common.annotation.architecture.ExternalApiAdapter;
76
import lombok.RequiredArgsConstructor;
@@ -20,34 +19,40 @@ public class AgitClient implements SendAgitPort {
2019
private String AGIT_WEBHOOK_URL;
2120

2221
@Override
23-
public void sendAgit(SendWebhookRequest request) {
24-
RestTemplate restTemplate = new RestTemplate();
25-
26-
String message = null;
27-
if (request.notificationType() == NotificationType.TASK_REQUESTED) {
28-
message = request.taskName() + " 작업이 요청되었습니다.";
29-
}
30-
else if (request.notificationType() == NotificationType.COMMENT) {
31-
message = request.taskName() + " 작업에 " + request.commenterName() + "님이 댓글을 남기셨습니다.";
32-
}
33-
else if (request.notificationType() == NotificationType.PROCESSOR_ASSIGNED) {
34-
message = request.taskName() + " 작업에 담당자(" + request.message() + ")가 배정되었습니다.";
35-
}
36-
else if (request.notificationType() == NotificationType.PROCESSOR_CHANGED) {
37-
message = request.taskName() + " 작업의 담당자가 " + request.message() + "로 변경되었습니다.";
38-
}
39-
else {
40-
message = request.taskName() + " 작업의 상태가 " + request.message() + "로 변경되었습니다";
41-
}
42-
43-
String payload = "{\"text\":\"" + message + "\"}";
22+
public void sendAgit(PushNotificationTemplate request) {
4423

4524
HttpHeaders headers = new HttpHeaders();
4625
headers.add("Content-Type", "application/json");
4726

27+
RestTemplate restTemplate = new RestTemplate();
28+
String taskUrl = "https://www.naver.com"; //Todo 작업 상세페이지 url 추가
29+
30+
String message = switch (request.notificationType()) {
31+
case TASK_REQUESTED -> "📌 *새 작업 요청:* `" + request.taskName() + "`\\n"
32+
+ "\\t\\t*•요청자: " + request.senderName() + "*\\n"
33+
+ "\\t\\t[OPEN](" + taskUrl + ")";
34+
case STATUS_SWITCHED -> "⚙️ *작업 상태 변경:* `" + request.taskName() + "\\n"
35+
+ "\\t\\t*•작업 상태: " + request.message() + "*\\n"
36+
+ "\\t\\t[OPEN](" + taskUrl + ")";
37+
case PROCESSOR_CHANGED -> "🔄 *담당자 변경:* `" + request.taskName() + "\\n"
38+
+ "\\t\\t*•새 담당자: " + request.message() + "*\\n"
39+
+ "\\t\\t[OPEN](" + taskUrl + ")";
40+
case PROCESSOR_ASSIGNED -> "👤 *작업 담당자 배정:* `" + request.taskName() + "\\n"
41+
+ "\\t\\t*•담당자: " + request.message() + "*\\n"
42+
+ "\\t\\t[OPEN](" + taskUrl + ")";
43+
case COMMENT -> "💬 *새 댓글:* `" + request.taskName() + "`\\n"
44+
+ "\\t\\t*•작성자: " + request.commenterName() + "\\n"
45+
+ "\\t\\t*•댓글 내용: " + request.message() + "\\n"
46+
+ "\\t\\t[OPEN](" + taskUrl + ")";
47+
default -> null;
48+
};
49+
50+
String payload = "{"
51+
+ "\"text\": \"" + message + "\","
52+
+ "\"mrkdwn\": true" + "}";
53+
4854
HttpEntity<String> entity = new HttpEntity<>(payload, headers);
4955

50-
// Post 요청
5156
restTemplate.exchange(AGIT_WEBHOOK_URL, HttpMethod.POST, entity, String.class);
5257
}
5358
}

src/main/java/clap/server/adapter/outbound/api/EmailClient.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package clap.server.adapter.outbound.api;
22

33
import clap.server.adapter.outbound.api.dto.EmailTemplate;
4-
import clap.server.adapter.outbound.api.dto.SendWebhookRequest;
4+
import clap.server.adapter.outbound.api.dto.PushNotificationTemplate;
55
import clap.server.application.port.outbound.webhook.SendEmailPort;
66
import clap.server.common.annotation.architecture.ExternalApiAdapter;
77
import clap.server.exception.AdapterException;
@@ -19,7 +19,7 @@ public class EmailClient implements SendEmailPort {
1919
private final JavaMailSender mailSender;
2020

2121
@Override
22-
public void sendWebhookEmail(SendWebhookRequest request) {
22+
public void sendWebhookEmail(PushNotificationTemplate request) {
2323
try {
2424
MimeMessage mimeMessage = mailSender.createMimeMessage();
2525
MimeMessageHelper helper = new MimeMessageHelper(mimeMessage, true, "UTF-8");

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

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package clap.server.adapter.outbound.api;
22

33
import clap.server.adapter.outbound.api.dto.EmailTemplate;
4-
import clap.server.adapter.outbound.api.dto.SendWebhookRequest;
4+
import clap.server.adapter.outbound.api.dto.PushNotificationTemplate;
55
import lombok.RequiredArgsConstructor;
66
import org.springframework.stereotype.Component;
77
import org.thymeleaf.context.Context;
@@ -10,39 +10,46 @@
1010
@Component
1111
@RequiredArgsConstructor
1212
public class EmailTemplateBuilder {
13+
1314
private final SpringTemplateEngine templateEngine;
1415

15-
public EmailTemplate createWebhookTemplate(SendWebhookRequest request) {
16+
public EmailTemplate createWebhookTemplate(PushNotificationTemplate request) {
1617
Context context = new Context();
1718
String templateName = "";
1819
String subject = "";
20+
String taskDetailUrl = "https://www.naver.com"; //ToDo task 상세 조회페이지 url 추가
1921
switch (request.notificationType()) {
2022
case TASK_REQUESTED:
2123
templateName = "task-request";
2224
subject = "[TaskFlow 알림] 신규 작업이 요청되었습니다.";
25+
context.setVariable("taskDetailUrl", taskDetailUrl);
2326
context.setVariable("receiverName", request.senderName());
2427
context.setVariable("title", request.taskName());
2528
break;
2629
case STATUS_SWITCHED:
2730
templateName = "status-switched";
2831
subject = "[TaskFlow 알림] 작업 상태가 변경되었습니다.";
32+
context.setVariable("taskDetailUrl", taskDetailUrl);
2933
context.setVariable("receiverName", request.senderName());
3034
context.setVariable("title", request.taskName());
3135
break;
3236
case PROCESSOR_CHANGED:
3337
templateName = "processor-changed";
3438
subject = "[TaskFlow 알림] 작업 담당자가 변경되었습니다.";
39+
context.setVariable("taskDetailUrl", taskDetailUrl);
3540
context.setVariable("processorName", request.message());
3641
context.setVariable("title", request.taskName());
3742
break;
3843
case PROCESSOR_ASSIGNED:
3944
templateName = "processor-assigned";
4045
subject = "[TaskFlow 알림] 작업 담당자가 지정되었습니다.";
46+
context.setVariable("taskDetailUrl", taskDetailUrl);
4147
context.setVariable("processorName", request.message());
4248
context.setVariable("title", request.taskName());
4349
break;
4450
case COMMENT:
4551
subject = "[TaskFlow 알림] 댓글이 작성되었습니다.";
52+
context.setVariable("taskDetailUrl", taskDetailUrl);
4653
context.setVariable("comment", request.message());
4754
context.setVariable("title", request.taskName());
4855
break;

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

Lines changed: 26 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package clap.server.adapter.outbound.api;
22

3-
import clap.server.adapter.outbound.api.dto.SendWebhookRequest;
4-
import clap.server.adapter.outbound.persistense.entity.notification.constant.NotificationType;
3+
import clap.server.adapter.outbound.api.dto.PushNotificationTemplate;
54
import com.fasterxml.jackson.core.JsonProcessingException;
65
import com.fasterxml.jackson.databind.ObjectMapper;
76
import lombok.RequiredArgsConstructor;
@@ -15,36 +14,25 @@ public class KakaoWorkBlockBuilder {
1514

1615
private final ObjectMapper objectMapper;
1716

18-
public String makeObjectBlock(SendWebhookRequest request){
19-
String payload;
20-
if (request.notificationType() == NotificationType.TASK_REQUESTED) {
21-
payload = makeTaskRequestBlock(request);
22-
}
23-
else if (request.notificationType() == NotificationType.PROCESSOR_ASSIGNED) {
24-
payload = makeNewProcessorBlock(request);
25-
}
26-
else if (request.notificationType() == NotificationType.PROCESSOR_CHANGED) {
27-
payload = makeProcessorChangeBlock(request);
28-
}
29-
else if (request.notificationType() == NotificationType.STATUS_SWITCHED) {
30-
payload = makeTaskStatusBlock(request);
31-
}
32-
else {
33-
payload = makeCommentBlock(request);
34-
}
35-
return payload;
17+
public String makeObjectBlock(PushNotificationTemplate request){
18+
String taskDetailUrl = "https://www.naver.com";
19+
return switch (request.notificationType()) {
20+
case TASK_REQUESTED -> makeTaskRequestBlock(request, taskDetailUrl);
21+
case STATUS_SWITCHED -> makeTaskStatusBlock(request, taskDetailUrl);
22+
case PROCESSOR_CHANGED -> makeProcessorChangeBlock(request, taskDetailUrl);
23+
case PROCESSOR_ASSIGNED -> makeNewProcessorBlock(request, taskDetailUrl);
24+
case COMMENT -> makeCommentBlock(request, taskDetailUrl);
25+
default -> null;
26+
};
3627
}
3728

38-
private String makeTaskRequestBlock(SendWebhookRequest request) {
39-
// Blocks 데이터 생성
29+
private String makeTaskRequestBlock(PushNotificationTemplate request, String taskDetailUrl) {
4030
Object[] blocks = new Object[]{
41-
// Header 블록
4231
Map.of(
4332
"type", "header",
4433
"text", "TaskFlow 작업 요청 알림",
4534
"style", "blue"
4635
),
47-
// Text 블록 1
4836
Map.of(
4937
"type", "text",
5038
"text", "TaskFlow 작업 요청 알림",
@@ -56,7 +44,6 @@ private String makeTaskRequestBlock(SendWebhookRequest request) {
5644
)
5745
}
5846
),
59-
// Text 블록 2: 제목 변수 사용
6047
Map.of(
6148
"type", "text",
6249
"text", "TaskFlow 작업 요청 알림",
@@ -68,7 +55,6 @@ private String makeTaskRequestBlock(SendWebhookRequest request) {
6855
)
6956
}
7057
),
71-
// Text 블록 3: 요청자 변수 사용
7258
Map.of(
7359
"type", "text",
7460
"text", "TaskFlow 작업 요청 알림",
@@ -80,15 +66,14 @@ private String makeTaskRequestBlock(SendWebhookRequest request) {
8066
)
8167
}
8268
),
83-
// Button 블록
8469
Map.of(
8570
"type", "button",
8671
"text", "확인하기",
8772
"style", "default",
8873
"action", Map.of(
8974
"type", "open_system_browser",
9075
"name", "button1",
91-
"value", "http://example.com/details/999"
76+
"value", taskDetailUrl
9277
)
9378
)
9479
};
@@ -97,7 +82,7 @@ private String makeTaskRequestBlock(SendWebhookRequest request) {
9782
try {
9883
payload = "{" +
9984
"\"email\":\"" + request.email() + "\"," +
100-
"\"text\": \"신규 작업 요청 알림\"," + // fallback 메시지
85+
"\"text\": \"신규 작업 요청 알림\"," +
10186
"\"blocks\":" + objectMapper.writeValueAsString(blocks) +
10287
"}";
10388
} catch (JsonProcessingException e) {
@@ -107,7 +92,7 @@ private String makeTaskRequestBlock(SendWebhookRequest request) {
10792
return payload;
10893
}
10994

110-
private String makeNewProcessorBlock(SendWebhookRequest request) {
95+
private String makeNewProcessorBlock(PushNotificationTemplate request, String taskDetailUrl) {
11196
Object[] blocks = new Object[]{
11297
Map.of(
11398
"type", "header",
@@ -154,7 +139,7 @@ private String makeNewProcessorBlock(SendWebhookRequest request) {
154139
"action", Map.of(
155140
"type", "open_system_browser",
156141
"name", "button1",
157-
"value", "http://example.com/details/999"
142+
"value", taskDetailUrl
158143
)
159144
)
160145
};
@@ -163,7 +148,7 @@ private String makeNewProcessorBlock(SendWebhookRequest request) {
163148
try {
164149
payload = "{" +
165150
"\"email\":\"" + request.email() + "\"," +
166-
"\"text\":\"작업 담당자 선정 알림\"," + // fallback 메시지
151+
"\"text\":\"작업 담당자 선정 알림\"," +
167152
"\"blocks\":" + objectMapper.writeValueAsString(blocks) +
168153
"}";
169154
} catch (JsonProcessingException e) {
@@ -173,7 +158,7 @@ private String makeNewProcessorBlock(SendWebhookRequest request) {
173158
return payload;
174159
}
175160

176-
private String makeProcessorChangeBlock(SendWebhookRequest request) {
161+
private String makeProcessorChangeBlock(PushNotificationTemplate request, String taskDetailUrl) {
177162
Object[] blocks = new Object[]{
178163
Map.of(
179164
"type", "header",
@@ -220,7 +205,7 @@ private String makeProcessorChangeBlock(SendWebhookRequest request) {
220205
"action", Map.of(
221206
"type", "open_system_browser",
222207
"name", "button1",
223-
"value", "http://example.com/details/999"
208+
"value", taskDetailUrl
224209
)
225210
)
226211
};
@@ -229,7 +214,7 @@ private String makeProcessorChangeBlock(SendWebhookRequest request) {
229214
try {
230215
payload = "{" +
231216
"\"email\":\"" + request.email() + "\"," +
232-
"\"text\":\"작업 담당자 변경 알림\"," + // fallback 메시지
217+
"\"text\":\"작업 담당자 변경 알림\"," +
233218
"\"blocks\":" + objectMapper.writeValueAsString(blocks) +
234219
"}";
235220
} catch (JsonProcessingException e) {
@@ -240,7 +225,7 @@ private String makeProcessorChangeBlock(SendWebhookRequest request) {
240225
return payload;
241226
}
242227

243-
private String makeCommentBlock(SendWebhookRequest request) {
228+
private String makeCommentBlock(PushNotificationTemplate request, String taskDetailUrl) {
244229
Object[] blocks = new Object[]{
245230
Map.of(
246231
"type", "header",
@@ -298,7 +283,7 @@ private String makeCommentBlock(SendWebhookRequest request) {
298283
"action", Map.of(
299284
"type", "open_system_browser",
300285
"name", "button1",
301-
"value", "http://example.com/details/999"
286+
"value", taskDetailUrl
302287
)
303288
)
304289
};
@@ -307,7 +292,7 @@ private String makeCommentBlock(SendWebhookRequest request) {
307292
try {
308293
payload = "{" +
309294
"\"email\":\"" + request.email() + "\"," +
310-
"\"text\":\"댓글 알림\"," + // fallback 메시지
295+
"\"text\":\"댓글 알림\"," +
311296
"\"blocks\":" + objectMapper.writeValueAsString(blocks) +
312297
"}";
313298
} catch (JsonProcessingException e) {
@@ -317,7 +302,7 @@ private String makeCommentBlock(SendWebhookRequest request) {
317302
return payload;
318303
}
319304

320-
private String makeTaskStatusBlock(SendWebhookRequest request) {
305+
private String makeTaskStatusBlock(PushNotificationTemplate request, String taskDetailUrl) {
321306
Object[] blocks = new Object[]{
322307
Map.of(
323308
"type", "header",
@@ -364,7 +349,7 @@ private String makeTaskStatusBlock(SendWebhookRequest request) {
364349
"action", Map.of(
365350
"type", "open_system_browser",
366351
"name", "button1",
367-
"value", "http://example.com/details/999"
352+
"value", taskDetailUrl
368353
)
369354
)
370355
};
@@ -373,7 +358,7 @@ private String makeTaskStatusBlock(SendWebhookRequest request) {
373358
try {
374359
payload = "{" +
375360
"\"email\":\"" + request.email() + "\"," +
376-
"\"text\":\"작업 상태 변경 알림\"," + // fallback 메시지
361+
"\"text\":\"작업 상태 변경 알림\"," +
377362
"\"blocks\":" + objectMapper.writeValueAsString(blocks) +
378363
"}";
379364
} catch (JsonProcessingException e) {

src/main/java/clap/server/adapter/outbound/api/KakaoWorkClient.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package clap.server.adapter.outbound.api;
22

3-
import clap.server.adapter.outbound.api.dto.SendWebhookRequest;
3+
import clap.server.adapter.outbound.api.dto.PushNotificationTemplate;
44
import clap.server.application.port.outbound.webhook.SendKaKaoWorkPort;
55
import clap.server.common.annotation.architecture.ExternalApiAdapter;
66
import clap.server.exception.AdapterException;
@@ -25,7 +25,7 @@ public class KakaoWorkClient implements SendKaKaoWorkPort {
2525
private final KakaoWorkBlockBuilder kakaoWorkBlockBuilder;
2626

2727
@Override
28-
public void sendKakaoWork(SendWebhookRequest request) {
28+
public void sendKakaoWork(PushNotificationTemplate request) {
2929
RestTemplate restTemplate = new RestTemplate();
3030

3131
// Payload 생성

src/main/java/clap/server/adapter/outbound/api/dto/SendWebhookRequest.java renamed to src/main/java/clap/server/adapter/outbound/api/dto/PushNotificationTemplate.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@
22

33
import clap.server.adapter.outbound.persistense.entity.notification.constant.NotificationType;
44

5-
public record SendWebhookRequest(
5+
public record PushNotificationTemplate(
66

7+
Long taskId,
78
String email,
89
NotificationType notificationType,
910
String taskName,
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package clap.server.application.port.outbound.webhook;
22

3-
import clap.server.adapter.outbound.api.dto.SendWebhookRequest;
3+
import clap.server.adapter.outbound.api.dto.PushNotificationTemplate;
44

55
public interface SendAgitPort {
6-
void sendAgit(SendWebhookRequest request);
6+
void sendAgit(PushNotificationTemplate request);
77
}

0 commit comments

Comments
 (0)