diff --git a/src/main/java/clap/server/adapter/outbound/api/AgitClient.java b/src/main/java/clap/server/adapter/outbound/api/AgitClient.java index 6435e014..257b4bbe 100644 --- a/src/main/java/clap/server/adapter/outbound/api/AgitClient.java +++ b/src/main/java/clap/server/adapter/outbound/api/AgitClient.java @@ -29,9 +29,9 @@ public class AgitClient implements SendAgitPort { private final ObjectMapper objectMapper; @Override - public Long sendAgit(PushNotificationTemplate request, Task task) { + public Long sendAgit(PushNotificationTemplate request, Task task, String taskDetailUrl) { - HttpEntity entity = agitTemplateBuilder.createAgitEntity(request, task); + HttpEntity entity = agitTemplateBuilder.createAgitEntity(request, task, taskDetailUrl); RestTemplate restTemplate = new RestTemplate(); if (request.notificationType() == NotificationType.TASK_REQUESTED) { diff --git a/src/main/java/clap/server/adapter/outbound/api/AgitTemplateBuilder.java b/src/main/java/clap/server/adapter/outbound/api/AgitTemplateBuilder.java index 77091d0d..82ece92a 100644 --- a/src/main/java/clap/server/adapter/outbound/api/AgitTemplateBuilder.java +++ b/src/main/java/clap/server/adapter/outbound/api/AgitTemplateBuilder.java @@ -10,8 +10,8 @@ @Component public class AgitTemplateBuilder { - public HttpEntity createAgitEntity(PushNotificationTemplate request, Task task) { - return new HttpEntity<>(createPayLoad(request, task), createHeaders()); + public HttpEntity createAgitEntity(PushNotificationTemplate request, Task task, String taskDetailUrl) { + return new HttpEntity<>(createPayLoad(request, task, taskDetailUrl), createHeaders()); } @@ -21,41 +21,40 @@ public HttpHeaders createHeaders() { return headers; } - public String createPayLoad(PushNotificationTemplate request, Task task) { + public String createPayLoad(PushNotificationTemplate request, Task task, String taskDetailUrl) { String payload; if (request.notificationType() == NotificationType.TASK_REQUESTED) { payload = "{" - + "\"text\": \"" + createMessage(request) + "\"," + + "\"text\": \"" + createMessage(request, taskDetailUrl) + "\"," + "\"mrkdwn\": true" + "}"; } else { payload = "{" + "\"parent_id\": " + task.getAgitPostId() + "," - + "\"text\": \"" + createMessage(request) + "\"," + + "\"text\": \"" + createMessage(request, taskDetailUrl) + "\"," + "\"mrkdwn\": true" + "}"; } return payload; } - public String createMessage(PushNotificationTemplate request) { - String taskUrl = "https://www.naver.com"; //Todo 작업 상세페이지 url 추가 + public String createMessage(PushNotificationTemplate request, String taskDetailUrl) { return switch (request.notificationType()) { case TASK_REQUESTED -> "📌 *새 작업 요청:* `" + request.taskName() + "`\\n" + "\\t\\t*•요청자: " + request.senderName() + "*\\n" - + "\\t\\t[OPEN](" + taskUrl + ")"; + + "[확인하러 가기](" + taskDetailUrl + ")"; case STATUS_SWITCHED -> "⚙️ *작업 상태 변경:* `" + request.taskName() + "\\n" + "\\t\\t*•작업 상태: " + request.message() + "*\\n" - + "\\t\\t[OPEN](" + taskUrl + ")"; + + "[확인하러 가기](" + taskDetailUrl + ")"; case PROCESSOR_CHANGED -> "🔄 *담당자 변경:* `" + request.taskName() + "\\n" + "\\t\\t*•새 담당자: " + request.message() + "*\\n" - + "\\t\\t[OPEN](" + taskUrl + ")"; + + "[확인하러 가기](" + taskDetailUrl + ")"; case PROCESSOR_ASSIGNED -> "👤 *작업 담당자 배정:* `" + request.taskName() + "\\n" + "\\t\\t*•담당자: " + request.message() + "*\\n" - + "\\t\\t[OPEN](" + taskUrl + ")"; + + "[확인하러 가기](" + taskDetailUrl + ")"; default -> null; }; } diff --git a/src/main/java/clap/server/application/port/outbound/webhook/SendAgitPort.java b/src/main/java/clap/server/application/port/outbound/webhook/SendAgitPort.java index 9a0f0b3c..97dae006 100644 --- a/src/main/java/clap/server/application/port/outbound/webhook/SendAgitPort.java +++ b/src/main/java/clap/server/application/port/outbound/webhook/SendAgitPort.java @@ -4,5 +4,5 @@ import clap.server.domain.model.task.Task; public interface SendAgitPort { - Long sendAgit(PushNotificationTemplate request, Task task); + Long sendAgit(PushNotificationTemplate request, Task task, String taskDetailUrl); } diff --git a/src/main/java/clap/server/application/service/webhook/SendAgitService.java b/src/main/java/clap/server/application/service/webhook/SendAgitService.java index d22a7f79..77f4eea1 100644 --- a/src/main/java/clap/server/application/service/webhook/SendAgitService.java +++ b/src/main/java/clap/server/application/service/webhook/SendAgitService.java @@ -15,8 +15,8 @@ public class SendAgitService { private final SendAgitPort agitPort; private final TaskService taskService; - public void sendAgit(PushNotificationTemplate request, Task task) { - Long agitPostId = agitPort.sendAgit(request, task); + public void sendAgit(PushNotificationTemplate request, Task task, String taskDetailUrl) { + Long agitPostId = agitPort.sendAgit(request, task, taskDetailUrl); if (request.notificationType().equals(NotificationType.TASK_REQUESTED)) { task.updateAgitPostId(agitPostId); diff --git a/src/main/java/clap/server/application/service/webhook/SendNotificationService.java b/src/main/java/clap/server/application/service/webhook/SendNotificationService.java index b1fc7b8e..473a37b5 100644 --- a/src/main/java/clap/server/application/service/webhook/SendNotificationService.java +++ b/src/main/java/clap/server/application/service/webhook/SendNotificationService.java @@ -18,7 +18,7 @@ @RequiredArgsConstructor public class SendNotificationService { - private final SendSseService sendSseService; + //private final SendSseService sendSseService; private final SendAgitService sendAgitService; private final SendWebhookEmailService sendWebhookEmailService; private final SendKaKaoWorkService sendKaKaoWorkService; @@ -74,19 +74,6 @@ public void sendPushNotification(Member receiver, NotificationType notificationT allOf.join(); } - private String extractTaskUrl(NotificationType notificationType, Task task, Boolean isManager) { - String taskDetailUrl = "http://localhost:5173/my-request?taskId=" + task.getTaskId(); - if (isManager) { - if (notificationType == NotificationType.TASK_REQUESTED) { - taskDetailUrl = "http://localhost:5173/requested?taskId=" + task.getTaskId(); - } - else { - taskDetailUrl = "http://localhost:5173/my-task?taskId=" + task.getTaskId(); - } - } - return taskDetailUrl; - } - @Async("notificationExecutor") public void sendAgitNotification(NotificationType notificationType, Task task, String message, String commenterName) { @@ -98,6 +85,22 @@ public void sendAgitNotification(NotificationType notificationType, message, commenterName ); - sendAgitService.sendAgit(pushNotificationTemplate, task); + + String taskDetailUrl = extractTaskUrl(notificationType, task, true); + + sendAgitService.sendAgit(pushNotificationTemplate, task, taskDetailUrl); + } + + private String extractTaskUrl(NotificationType notificationType, Task task, Boolean isManager) { + String taskDetailUrl = "http://localhost:5173/my-request?taskId=" + task.getTaskId(); + if (isManager) { + if (notificationType == NotificationType.TASK_REQUESTED) { + taskDetailUrl = "http://localhost:5173/requested?taskId=" + task.getTaskId(); + } + else { + taskDetailUrl = "http://localhost:5173/my-task?taskId=" + task.getTaskId(); + } + } + return taskDetailUrl; } }