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
@@ -1,4 +1,4 @@
package clap.server.adapter.inbound.web.dto.history;
package clap.server.adapter.inbound.web.dto.history.request;

import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.NotBlank;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package clap.server.adapter.inbound.web.dto.history;
package clap.server.adapter.inbound.web.dto.history.request;

import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.NotBlank;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package clap.server.adapter.inbound.web.history;

import clap.server.adapter.inbound.security.SecurityUserDetails;
import clap.server.adapter.inbound.web.dto.history.EditCommentRequest;
import clap.server.adapter.inbound.web.dto.history.request.EditCommentRequest;
import clap.server.application.port.inbound.history.DeleteCommentUsecase;
import clap.server.application.port.inbound.history.EditCommentUsecase;
import clap.server.common.annotation.architecture.WebAdapter;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package clap.server.adapter.inbound.web.history;

import clap.server.adapter.inbound.security.SecurityUserDetails;
import clap.server.adapter.inbound.web.dto.history.CreateCommentRequest;
import clap.server.adapter.inbound.web.dto.history.request.CreateCommentRequest;
import clap.server.application.port.inbound.history.SaveCommentAttachmentUsecase;
import clap.server.application.port.inbound.history.SaveCommentUsecase;
import clap.server.common.annotation.architecture.WebAdapter;
Expand Down
53 changes: 29 additions & 24 deletions src/main/java/clap/server/adapter/outbound/api/AgitClient.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package clap.server.adapter.outbound.api;

import clap.server.adapter.outbound.api.dto.SendWebhookRequest;
import clap.server.adapter.outbound.persistense.entity.notification.constant.NotificationType;
import clap.server.adapter.outbound.api.dto.PushNotificationTemplate;
import clap.server.application.port.outbound.webhook.SendAgitPort;
import clap.server.common.annotation.architecture.ExternalApiAdapter;
import lombok.RequiredArgsConstructor;
Expand All @@ -20,34 +19,40 @@ public class AgitClient implements SendAgitPort {
private String AGIT_WEBHOOK_URL;

@Override
public void sendAgit(SendWebhookRequest request) {
RestTemplate restTemplate = new RestTemplate();

String message = null;
if (request.notificationType() == NotificationType.TASK_REQUESTED) {
message = request.taskName() + " 작업이 요청되었습니다.";
}
else if (request.notificationType() == NotificationType.COMMENT) {
message = request.taskName() + " 작업에 " + request.commenterName() + "님이 댓글을 남기셨습니다.";
}
else if (request.notificationType() == NotificationType.PROCESSOR_ASSIGNED) {
message = request.taskName() + " 작업에 담당자(" + request.message() + ")가 배정되었습니다.";
}
else if (request.notificationType() == NotificationType.PROCESSOR_CHANGED) {
message = request.taskName() + " 작업의 담당자가 " + request.message() + "로 변경되었습니다.";
}
else {
message = request.taskName() + " 작업의 상태가 " + request.message() + "로 변경되었습니다";
}

String payload = "{\"text\":\"" + message + "\"}";
public void sendAgit(PushNotificationTemplate request) {

HttpHeaders headers = new HttpHeaders();
headers.add("Content-Type", "application/json");

RestTemplate restTemplate = new RestTemplate();
String taskUrl = "https://www.naver.com"; //Todo 작업 상세페이지 url 추가

String message = switch (request.notificationType()) {
case TASK_REQUESTED -> "📌 *새 작업 요청:* `" + request.taskName() + "`\\n"
+ "\\t\\t*•요청자: " + request.senderName() + "*\\n"
+ "\\t\\t[OPEN](" + taskUrl + ")";
case STATUS_SWITCHED -> "⚙️ *작업 상태 변경:* `" + request.taskName() + "\\n"
+ "\\t\\t*•작업 상태: " + request.message() + "*\\n"
+ "\\t\\t[OPEN](" + taskUrl + ")";
case PROCESSOR_CHANGED -> "🔄 *담당자 변경:* `" + request.taskName() + "\\n"
+ "\\t\\t*•새 담당자: " + request.message() + "*\\n"
+ "\\t\\t[OPEN](" + taskUrl + ")";
case PROCESSOR_ASSIGNED -> "👤 *작업 담당자 배정:* `" + request.taskName() + "\\n"
+ "\\t\\t*•담당자: " + request.message() + "*\\n"
+ "\\t\\t[OPEN](" + taskUrl + ")";
case COMMENT -> "💬 *새 댓글:* `" + request.taskName() + "`\\n"
+ "\\t\\t*•작성자: " + request.commenterName() + "\\n"
+ "\\t\\t*•댓글 내용: " + request.message() + "\\n"
+ "\\t\\t[OPEN](" + taskUrl + ")";
default -> null;
};

String payload = "{"
+ "\"text\": \"" + message + "\","
+ "\"mrkdwn\": true" + "}";

HttpEntity<String> entity = new HttpEntity<>(payload, headers);

// Post 요청
restTemplate.exchange(AGIT_WEBHOOK_URL, HttpMethod.POST, entity, String.class);
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package clap.server.adapter.outbound.api;

import clap.server.adapter.outbound.api.dto.EmailTemplate;
import clap.server.adapter.outbound.api.dto.SendWebhookRequest;
import clap.server.adapter.outbound.api.dto.PushNotificationTemplate;
import clap.server.application.port.outbound.webhook.SendEmailPort;
import clap.server.common.annotation.architecture.ExternalApiAdapter;
import clap.server.exception.AdapterException;
Expand All @@ -19,7 +19,7 @@ public class EmailClient implements SendEmailPort {
private final JavaMailSender mailSender;

@Override
public void sendWebhookEmail(SendWebhookRequest request) {
public void sendWebhookEmail(PushNotificationTemplate request) {
try {
MimeMessage mimeMessage = mailSender.createMimeMessage();
MimeMessageHelper helper = new MimeMessageHelper(mimeMessage, true, "UTF-8");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package clap.server.adapter.outbound.api;

import clap.server.adapter.outbound.api.dto.EmailTemplate;
import clap.server.adapter.outbound.api.dto.SendWebhookRequest;
import clap.server.adapter.outbound.api.dto.PushNotificationTemplate;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Component;
import org.thymeleaf.context.Context;
Expand All @@ -10,39 +10,46 @@
@Component
@RequiredArgsConstructor
public class EmailTemplateBuilder {

private final SpringTemplateEngine templateEngine;

public EmailTemplate createWebhookTemplate(SendWebhookRequest request) {
public EmailTemplate createWebhookTemplate(PushNotificationTemplate request) {
Context context = new Context();
String templateName = "";
String subject = "";
String taskDetailUrl = "https://www.naver.com"; //ToDo task 상세 조회페이지 url 추가
switch (request.notificationType()) {
case TASK_REQUESTED:
templateName = "task-request";
subject = "[TaskFlow 알림] 신규 작업이 요청되었습니다.";
context.setVariable("taskDetailUrl", taskDetailUrl);
context.setVariable("receiverName", request.senderName());
context.setVariable("title", request.taskName());
break;
case STATUS_SWITCHED:
templateName = "status-switched";
subject = "[TaskFlow 알림] 작업 상태가 변경되었습니다.";
context.setVariable("taskDetailUrl", taskDetailUrl);
context.setVariable("receiverName", request.senderName());
context.setVariable("title", request.taskName());
break;
case PROCESSOR_CHANGED:
templateName = "processor-changed";
subject = "[TaskFlow 알림] 작업 담당자가 변경되었습니다.";
context.setVariable("taskDetailUrl", taskDetailUrl);
context.setVariable("processorName", request.message());
context.setVariable("title", request.taskName());
break;
case PROCESSOR_ASSIGNED:
templateName = "processor-assigned";
subject = "[TaskFlow 알림] 작업 담당자가 지정되었습니다.";
context.setVariable("taskDetailUrl", taskDetailUrl);
context.setVariable("processorName", request.message());
context.setVariable("title", request.taskName());
break;
case COMMENT:
subject = "[TaskFlow 알림] 댓글이 작성되었습니다.";
context.setVariable("taskDetailUrl", taskDetailUrl);
context.setVariable("comment", request.message());
context.setVariable("title", request.taskName());
break;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package clap.server.adapter.outbound.api;

import clap.server.adapter.outbound.api.dto.SendWebhookRequest;
import clap.server.adapter.outbound.persistense.entity.notification.constant.NotificationType;
import clap.server.adapter.outbound.api.dto.PushNotificationTemplate;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import lombok.RequiredArgsConstructor;
Expand All @@ -15,36 +14,25 @@ public class KakaoWorkBlockBuilder {

private final ObjectMapper objectMapper;

public String makeObjectBlock(SendWebhookRequest request){
String payload;
if (request.notificationType() == NotificationType.TASK_REQUESTED) {
payload = makeTaskRequestBlock(request);
}
else if (request.notificationType() == NotificationType.PROCESSOR_ASSIGNED) {
payload = makeNewProcessorBlock(request);
}
else if (request.notificationType() == NotificationType.PROCESSOR_CHANGED) {
payload = makeProcessorChangeBlock(request);
}
else if (request.notificationType() == NotificationType.STATUS_SWITCHED) {
payload = makeTaskStatusBlock(request);
}
else {
payload = makeCommentBlock(request);
}
return payload;
public String makeObjectBlock(PushNotificationTemplate request){
String taskDetailUrl = "https://www.naver.com";
return switch (request.notificationType()) {
case TASK_REQUESTED -> makeTaskRequestBlock(request, taskDetailUrl);
case STATUS_SWITCHED -> makeTaskStatusBlock(request, taskDetailUrl);
case PROCESSOR_CHANGED -> makeProcessorChangeBlock(request, taskDetailUrl);
case PROCESSOR_ASSIGNED -> makeNewProcessorBlock(request, taskDetailUrl);
case COMMENT -> makeCommentBlock(request, taskDetailUrl);
default -> null;
};
}

private String makeTaskRequestBlock(SendWebhookRequest request) {
// Blocks 데이터 생성
private String makeTaskRequestBlock(PushNotificationTemplate request, String taskDetailUrl) {
Object[] blocks = new Object[]{
// Header 블록
Map.of(
"type", "header",
"text", "TaskFlow 작업 요청 알림",
"style", "blue"
),
// Text 블록 1
Map.of(
"type", "text",
"text", "TaskFlow 작업 요청 알림",
Expand All @@ -56,7 +44,6 @@ private String makeTaskRequestBlock(SendWebhookRequest request) {
)
}
),
// Text 블록 2: 제목 변수 사용
Map.of(
"type", "text",
"text", "TaskFlow 작업 요청 알림",
Expand All @@ -68,7 +55,6 @@ private String makeTaskRequestBlock(SendWebhookRequest request) {
)
}
),
// Text 블록 3: 요청자 변수 사용
Map.of(
"type", "text",
"text", "TaskFlow 작업 요청 알림",
Expand All @@ -80,15 +66,14 @@ private String makeTaskRequestBlock(SendWebhookRequest request) {
)
}
),
// Button 블록
Map.of(
"type", "button",
"text", "확인하기",
"style", "default",
"action", Map.of(
"type", "open_system_browser",
"name", "button1",
"value", "http://example.com/details/999"
"value", taskDetailUrl
)
)
};
Expand All @@ -97,7 +82,7 @@ private String makeTaskRequestBlock(SendWebhookRequest request) {
try {
payload = "{" +
"\"email\":\"" + request.email() + "\"," +
"\"text\": \"신규 작업 요청 알림\"," + // fallback 메시지
"\"text\": \"신규 작업 요청 알림\"," +
"\"blocks\":" + objectMapper.writeValueAsString(blocks) +
"}";
} catch (JsonProcessingException e) {
Expand All @@ -107,7 +92,7 @@ private String makeTaskRequestBlock(SendWebhookRequest request) {
return payload;
}

private String makeNewProcessorBlock(SendWebhookRequest request) {
private String makeNewProcessorBlock(PushNotificationTemplate request, String taskDetailUrl) {
Object[] blocks = new Object[]{
Map.of(
"type", "header",
Expand Down Expand Up @@ -154,7 +139,7 @@ private String makeNewProcessorBlock(SendWebhookRequest request) {
"action", Map.of(
"type", "open_system_browser",
"name", "button1",
"value", "http://example.com/details/999"
"value", taskDetailUrl
)
)
};
Expand All @@ -163,7 +148,7 @@ private String makeNewProcessorBlock(SendWebhookRequest request) {
try {
payload = "{" +
"\"email\":\"" + request.email() + "\"," +
"\"text\":\"작업 담당자 선정 알림\"," + // fallback 메시지
"\"text\":\"작업 담당자 선정 알림\"," +
"\"blocks\":" + objectMapper.writeValueAsString(blocks) +
"}";
} catch (JsonProcessingException e) {
Expand All @@ -173,7 +158,7 @@ private String makeNewProcessorBlock(SendWebhookRequest request) {
return payload;
}

private String makeProcessorChangeBlock(SendWebhookRequest request) {
private String makeProcessorChangeBlock(PushNotificationTemplate request, String taskDetailUrl) {
Object[] blocks = new Object[]{
Map.of(
"type", "header",
Expand Down Expand Up @@ -220,7 +205,7 @@ private String makeProcessorChangeBlock(SendWebhookRequest request) {
"action", Map.of(
"type", "open_system_browser",
"name", "button1",
"value", "http://example.com/details/999"
"value", taskDetailUrl
)
)
};
Expand All @@ -229,7 +214,7 @@ private String makeProcessorChangeBlock(SendWebhookRequest request) {
try {
payload = "{" +
"\"email\":\"" + request.email() + "\"," +
"\"text\":\"작업 담당자 변경 알림\"," + // fallback 메시지
"\"text\":\"작업 담당자 변경 알림\"," +
"\"blocks\":" + objectMapper.writeValueAsString(blocks) +
"}";
} catch (JsonProcessingException e) {
Expand All @@ -240,7 +225,7 @@ private String makeProcessorChangeBlock(SendWebhookRequest request) {
return payload;
}

private String makeCommentBlock(SendWebhookRequest request) {
private String makeCommentBlock(PushNotificationTemplate request, String taskDetailUrl) {
Object[] blocks = new Object[]{
Map.of(
"type", "header",
Expand Down Expand Up @@ -298,7 +283,7 @@ private String makeCommentBlock(SendWebhookRequest request) {
"action", Map.of(
"type", "open_system_browser",
"name", "button1",
"value", "http://example.com/details/999"
"value", taskDetailUrl
)
)
};
Expand All @@ -307,7 +292,7 @@ private String makeCommentBlock(SendWebhookRequest request) {
try {
payload = "{" +
"\"email\":\"" + request.email() + "\"," +
"\"text\":\"댓글 알림\"," + // fallback 메시지
"\"text\":\"댓글 알림\"," +
"\"blocks\":" + objectMapper.writeValueAsString(blocks) +
"}";
} catch (JsonProcessingException e) {
Expand All @@ -317,7 +302,7 @@ private String makeCommentBlock(SendWebhookRequest request) {
return payload;
}

private String makeTaskStatusBlock(SendWebhookRequest request) {
private String makeTaskStatusBlock(PushNotificationTemplate request, String taskDetailUrl) {
Object[] blocks = new Object[]{
Map.of(
"type", "header",
Expand Down Expand Up @@ -364,7 +349,7 @@ private String makeTaskStatusBlock(SendWebhookRequest request) {
"action", Map.of(
"type", "open_system_browser",
"name", "button1",
"value", "http://example.com/details/999"
"value", taskDetailUrl
)
)
};
Expand All @@ -373,7 +358,7 @@ private String makeTaskStatusBlock(SendWebhookRequest request) {
try {
payload = "{" +
"\"email\":\"" + request.email() + "\"," +
"\"text\":\"작업 상태 변경 알림\"," + // fallback 메시지
"\"text\":\"작업 상태 변경 알림\"," +
"\"blocks\":" + objectMapper.writeValueAsString(blocks) +
"}";
} catch (JsonProcessingException e) {
Expand Down
Loading
Loading