Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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<String> entity = agitTemplateBuilder.createAgitEntity(request, task);
HttpEntity<String> entity = agitTemplateBuilder.createAgitEntity(request, task, taskDetailUrl);

RestTemplate restTemplate = new RestTemplate();
if (request.notificationType() == NotificationType.TASK_REQUESTED) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
@Component
public class AgitTemplateBuilder {

public HttpEntity<String> createAgitEntity(PushNotificationTemplate request, Task task) {
return new HttpEntity<>(createPayLoad(request, task), createHeaders());
public HttpEntity<String> createAgitEntity(PushNotificationTemplate request, Task task, String taskDetailUrl) {
return new HttpEntity<>(createPayLoad(request, task, taskDetailUrl), createHeaders());
}


Expand All @@ -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;
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand All @@ -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;
}
}