22
33import clap .server .adapter .outbound .api .dto .PushNotificationTemplate ;
44import clap .server .adapter .outbound .persistense .entity .notification .constant .NotificationType ;
5- import clap .server .application .port .outbound .task .CommandTaskPort ;
65import clap .server .application .port .outbound .webhook .SendAgitPort ;
6+ import clap .server .application .service .task .UpdateTaskService ;
77import clap .server .common .annotation .architecture .ExternalApiAdapter ;
88import clap .server .domain .model .task .Task ;
99import lombok .RequiredArgsConstructor ;
1010import org .springframework .beans .factory .annotation .Value ;
1111import org .springframework .http .HttpEntity ;
12- import org .springframework .http .HttpHeaders ;
1312import org .springframework .http .HttpMethod ;
1413import org .springframework .http .ResponseEntity ;
1514import 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}
0 commit comments