Skip to content

Commit 3de68ff

Browse files
committed
CLAP-257 Fix : template builder 클래스로 agit template 생성 기능 분리
1 parent 031640e commit 3de68ff

File tree

2 files changed

+67
-49
lines changed

2 files changed

+67
-49
lines changed

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

Lines changed: 5 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,13 @@
22

33
import clap.server.adapter.outbound.api.dto.PushNotificationTemplate;
44
import clap.server.adapter.outbound.persistense.entity.notification.constant.NotificationType;
5-
import clap.server.application.port.outbound.task.CommandTaskPort;
65
import clap.server.application.port.outbound.webhook.SendAgitPort;
6+
import clap.server.application.service.task.UpdateTaskService;
77
import clap.server.common.annotation.architecture.ExternalApiAdapter;
88
import clap.server.domain.model.task.Task;
99
import lombok.RequiredArgsConstructor;
1010
import org.springframework.beans.factory.annotation.Value;
1111
import org.springframework.http.HttpEntity;
12-
import org.springframework.http.HttpHeaders;
1312
import org.springframework.http.HttpMethod;
1413
import org.springframework.http.ResponseEntity;
1514
import org.springframework.web.client.RestTemplate;
@@ -22,65 +21,22 @@ public class AgitClient implements SendAgitPort {
2221
@Value("${webhook.agit.url}")
2322
private String AGIT_WEBHOOK_URL;
2423

25-
private final CommandTaskPort commandTaskPort;
24+
private final UpdateTaskService updateTaskService;
25+
private final AgitTemplateBuilder agitTemplateBuilder;
2626

2727
@Override
2828
public void sendAgit(PushNotificationTemplate request, Task task) {
2929

30-
HttpHeaders headers = new HttpHeaders();
31-
32-
headers.add("Content-Type", "application/json");
33-
HttpEntity<String> entity = new HttpEntity<>(getPayLoad(request, task), headers);
30+
HttpEntity<String> entity = agitTemplateBuilder.createAgitEntity(request, task);
3431

3532
RestTemplate restTemplate = new RestTemplate();
36-
37-
3833
if (request.notificationType() == NotificationType.TASK_REQUESTED) {
3934
ResponseEntity<String> responseEntity = restTemplate.exchange(
4035
AGIT_WEBHOOK_URL, HttpMethod.POST, entity, String.class);
41-
commandTaskPort.updateAgitPostId(responseEntity, task);
36+
updateTaskService.updateAgitPostId(responseEntity, task);
4237
}
4338
else {
4439
restTemplate.exchange(AGIT_WEBHOOK_URL, HttpMethod.POST, entity, String.class);
4540
}
4641
}
47-
48-
private String getPayLoad(PushNotificationTemplate request, Task task) {
49-
50-
String payload;
51-
if (request.notificationType() == NotificationType.TASK_REQUESTED) {
52-
payload = "{"
53-
+ "\"text\": \"" + getMessage(request) + "\","
54-
+ "\"mrkdwn\": true" + "}";
55-
}
56-
57-
else {
58-
payload = "{"
59-
+ "\"parent_id\": " + task.getAgitPostId() + ","
60-
+ "\"text\": \"" + getMessage(request) + "\","
61-
+ "\"mrkdwn\": true"
62-
+ "}";
63-
}
64-
return payload;
65-
}
66-
67-
private String getMessage(PushNotificationTemplate request) {
68-
String taskUrl = "https://www.naver.com"; //Todo 작업 상세페이지 url 추가
69-
70-
return switch (request.notificationType()) {
71-
case TASK_REQUESTED -> "📌 *새 작업 요청:* `" + request.taskName() + "`\\n"
72-
+ "\\t\\t*•요청자: " + request.senderName() + "*\\n"
73-
+ "\\t\\t[OPEN](" + taskUrl + ")";
74-
case STATUS_SWITCHED -> "⚙️ *작업 상태 변경:* `" + request.taskName() + "\\n"
75-
+ "\\t\\t*•작업 상태: " + request.message() + "*\\n"
76-
+ "\\t\\t[OPEN](" + taskUrl + ")";
77-
case PROCESSOR_CHANGED -> "🔄 *담당자 변경:* `" + request.taskName() + "\\n"
78-
+ "\\t\\t*•새 담당자: " + request.message() + "*\\n"
79-
+ "\\t\\t[OPEN](" + taskUrl + ")";
80-
case PROCESSOR_ASSIGNED -> "👤 *작업 담당자 배정:* `" + request.taskName() + "\\n"
81-
+ "\\t\\t*•담당자: " + request.message() + "*\\n"
82-
+ "\\t\\t[OPEN](" + taskUrl + ")";
83-
default -> null;
84-
};
85-
}
8642
}
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
package clap.server.adapter.outbound.api;
2+
3+
import clap.server.adapter.outbound.api.dto.PushNotificationTemplate;
4+
import clap.server.adapter.outbound.persistense.entity.notification.constant.NotificationType;
5+
import clap.server.domain.model.task.Task;
6+
import org.springframework.http.HttpEntity;
7+
import org.springframework.http.HttpHeaders;
8+
import org.springframework.stereotype.Component;
9+
10+
@Component
11+
public class AgitTemplateBuilder {
12+
13+
public HttpEntity<String> createAgitEntity(PushNotificationTemplate request, Task task) {
14+
return new HttpEntity<>(createPayLoad(request, task), createHeaders());
15+
}
16+
17+
18+
public HttpHeaders createHeaders() {
19+
HttpHeaders headers = new HttpHeaders();
20+
headers.add("Content-Type", "application/json");
21+
return headers;
22+
}
23+
24+
public String createPayLoad(PushNotificationTemplate request, Task task) {
25+
26+
String payload;
27+
if (request.notificationType() == NotificationType.TASK_REQUESTED) {
28+
payload = "{"
29+
+ "\"text\": \"" + createMessage(request) + "\","
30+
+ "\"mrkdwn\": true" + "}";
31+
}
32+
33+
else {
34+
payload = "{"
35+
+ "\"parent_id\": " + task.getAgitPostId() + ","
36+
+ "\"text\": \"" + createMessage(request) + "\","
37+
+ "\"mrkdwn\": true"
38+
+ "}";
39+
}
40+
return payload;
41+
}
42+
43+
public String createMessage(PushNotificationTemplate request) {
44+
String taskUrl = "https://www.naver.com"; //Todo 작업 상세페이지 url 추가
45+
46+
return switch (request.notificationType()) {
47+
case TASK_REQUESTED -> "📌 *새 작업 요청:* `" + request.taskName() + "`\\n"
48+
+ "\\t\\t*•요청자: " + request.senderName() + "*\\n"
49+
+ "\\t\\t[OPEN](" + taskUrl + ")";
50+
case STATUS_SWITCHED -> "⚙️ *작업 상태 변경:* `" + request.taskName() + "\\n"
51+
+ "\\t\\t*•작업 상태: " + request.message() + "*\\n"
52+
+ "\\t\\t[OPEN](" + taskUrl + ")";
53+
case PROCESSOR_CHANGED -> "🔄 *담당자 변경:* `" + request.taskName() + "\\n"
54+
+ "\\t\\t*•새 담당자: " + request.message() + "*\\n"
55+
+ "\\t\\t[OPEN](" + taskUrl + ")";
56+
case PROCESSOR_ASSIGNED -> "👤 *작업 담당자 배정:* `" + request.taskName() + "\\n"
57+
+ "\\t\\t*•담당자: " + request.message() + "*\\n"
58+
+ "\\t\\t[OPEN](" + taskUrl + ")";
59+
default -> null;
60+
};
61+
}
62+
}

0 commit comments

Comments
 (0)