-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathAgitTemplateBuilder.java
More file actions
61 lines (51 loc) · 2.63 KB
/
AgitTemplateBuilder.java
File metadata and controls
61 lines (51 loc) · 2.63 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
package clap.server.adapter.outbound.api.agit;
import clap.server.adapter.outbound.api.data.PushNotificationTemplate;
import clap.server.adapter.outbound.persistense.entity.notification.constant.NotificationType;
import clap.server.domain.model.task.Task;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.stereotype.Component;
@Component
public class AgitTemplateBuilder {
public HttpEntity<String> createAgitEntity(PushNotificationTemplate request, Task task, String taskDetailUrl) {
return new HttpEntity<>(createPayLoad(request, task, taskDetailUrl), createHeaders());
}
public HttpHeaders createHeaders() {
HttpHeaders headers = new HttpHeaders();
headers.add("Content-Type", "application/json");
return headers;
}
public String createPayLoad(PushNotificationTemplate request, Task task, String taskDetailUrl) {
String payload;
if (request.notificationType() == NotificationType.TASK_REQUESTED) {
payload = "{"
+ "\"text\": \"" + createMessage(request, taskDetailUrl) + "\","
+ "\"mrkdwn\": true" + "}";
}
else {
payload = "{"
+ "\"parent_id\": " + task.getAgitPostId() + ","
+ "\"text\": \"" + createMessage(request, taskDetailUrl) + "\","
+ "\"mrkdwn\": true"
+ "}";
}
return payload;
}
public String createMessage(PushNotificationTemplate request, String taskDetailUrl) {
return switch (request.notificationType()) {
case TASK_REQUESTED -> "📌 *새 작업 요청:* `" + request.taskName() + "`\\n"
+ "\\t\\t*•요청자: " + request.senderName() + "*\\n"
+ "[확인하러 가기](" + taskDetailUrl + ")";
case STATUS_SWITCHED -> "⚙️ *작업 상태 변경:* `" + request.taskName() + "\\n"
+ "\\t\\t*•작업 상태: " + request.message() + "*\\n"
+ "[확인하러 가기](" + taskDetailUrl + ")";
case PROCESSOR_CHANGED -> "🔄 *담당자 변경:* `" + request.taskName() + "\\n"
+ "\\t\\t*•새 담당자: " + request.message() + "*\\n"
+ "[확인하러 가기](" + taskDetailUrl + ")";
case PROCESSOR_ASSIGNED -> "👤 *작업 담당자 배정:* `" + request.taskName() + "\\n"
+ "\\t\\t*•담당자: " + request.message() + "*\\n"
+ "[확인하러 가기](" + taskDetailUrl + ")";
default -> null;
};
}
}