Skip to content

Commit 4022ced

Browse files
committed
CLAP-294 Refactor: agit post id 업데이트 로직 애플리케이션 단으로 이동
<footer> - 관련: #350
1 parent cd8f5d0 commit 4022ced

File tree

2 files changed

+20
-15
lines changed

2 files changed

+20
-15
lines changed

src/main/java/clap/server/adapter/outbound/api/AgitClient.java

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,10 @@
22

33
import clap.server.adapter.outbound.api.dto.PushNotificationTemplate;
44
import clap.server.adapter.outbound.persistense.entity.notification.constant.NotificationType;
5-
import clap.server.application.port.inbound.domain.TaskService;
65
import clap.server.application.port.outbound.webhook.SendAgitPort;
7-
import clap.server.application.service.task.UpdateTaskService;
86
import clap.server.common.annotation.architecture.ExternalApiAdapter;
97
import clap.server.domain.model.task.Task;
10-
import clap.server.exception.ApplicationException;
8+
import clap.server.exception.AdapterException;
119
import clap.server.exception.code.NotificationErrorCode;
1210
import com.fasterxml.jackson.core.JsonProcessingException;
1311
import com.fasterxml.jackson.databind.JsonNode;
@@ -29,31 +27,30 @@ public class AgitClient implements SendAgitPort {
2927

3028
private final AgitTemplateBuilder agitTemplateBuilder;
3129
private final ObjectMapper objectMapper;
32-
private final TaskService taskService;
3330

3431
@Override
35-
public void sendAgit(PushNotificationTemplate request, Task task) {
32+
public Long sendAgit(PushNotificationTemplate request, Task task) {
3633

3734
HttpEntity<String> entity = agitTemplateBuilder.createAgitEntity(request, task);
3835

3936
RestTemplate restTemplate = new RestTemplate();
4037
if (request.notificationType() == NotificationType.TASK_REQUESTED) {
4138
ResponseEntity<String> responseEntity = restTemplate.exchange(
4239
AGIT_WEBHOOK_URL, HttpMethod.POST, entity, String.class);
43-
updateAgitPostId(responseEntity, task);
40+
return getAgitPostId(responseEntity);
4441
}
4542
else {
4643
restTemplate.exchange(AGIT_WEBHOOK_URL, HttpMethod.POST, entity, String.class);
44+
return null;
4745
}
4846
}
4947

50-
private void updateAgitPostId(ResponseEntity<String> responseEntity, Task task) {
48+
private Long getAgitPostId(ResponseEntity<String> responseEntity) {
5149
try {
5250
JsonNode jsonNode = objectMapper.readTree(responseEntity.getBody());
53-
task.updateAgitPostId(jsonNode.get("id").asLong());
54-
taskService.upsert(task);
51+
return jsonNode.get("id").asLong();
5552
} catch (JsonProcessingException e) {
56-
throw new ApplicationException(NotificationErrorCode.AGIT_SEND_FAILED);
53+
throw new AdapterException(NotificationErrorCode.AGIT_SEND_FAILED);
5754
}
5855
}
5956
}

src/main/java/clap/server/application/service/webhook/SendNotificationService.java

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@
33
import clap.server.adapter.inbound.web.dto.notification.request.SseRequest;
44
import clap.server.adapter.outbound.api.dto.PushNotificationTemplate;
55
import clap.server.adapter.outbound.persistense.entity.notification.constant.NotificationType;
6+
import clap.server.application.port.inbound.domain.TaskService;
67
import clap.server.application.port.outbound.notification.CommandNotificationPort;
8+
import clap.server.application.port.outbound.webhook.SendSsePort;
79
import clap.server.common.annotation.architecture.ApplicationService;
810
import clap.server.domain.model.member.Member;
911
import clap.server.domain.model.notification.Notification;
@@ -18,11 +20,12 @@
1820
@RequiredArgsConstructor
1921
public class SendNotificationService {
2022

21-
private final SendSseService sendSseService;
23+
private final SendSsePort sendSsePort;
2224
private final SendAgitService sendAgitService;
2325
private final SendWebhookEmailService sendWebhookEmailService;
2426
private final SendKaKaoWorkService sendKaKaoWorkService;
2527
private final CommandNotificationPort commandNotificationPort;
28+
private final TaskService taskService;
2629

2730
@Async("notificationExecutor")
2831
public void sendPushNotification(Member receiver, NotificationType notificationType,
@@ -49,18 +52,18 @@ public void sendPushNotification(Member receiver, NotificationType notificationT
4952
});
5053

5154
CompletableFuture<Void> sendSseFuture = CompletableFuture.runAsync(() -> {
52-
sendSseService.send(sseRequest);
55+
sendSsePort.send(sseRequest);
5356
});
5457

5558
CompletableFuture<Void> sendEmailFuture = CompletableFuture.runAsync(() -> {
5659
if (receiver.getEmailNotificationEnabled()) {
57-
sendWebhookEmailService.sendEmail(pushNotificationTemplate);
60+
sendWebhookEmailService.send(pushNotificationTemplate);
5861
}
5962
});
6063

6164
CompletableFuture<Void> sendKakaoWorkFuture = CompletableFuture.runAsync(() -> {
6265
if (receiver.getKakaoworkNotificationEnabled()) {
63-
sendKaKaoWorkService.sendKaKaoWork(pushNotificationTemplate);
66+
sendKaKaoWorkService.send(pushNotificationTemplate);
6467
}
6568
});
6669

@@ -81,6 +84,11 @@ public void sendAgitNotification(NotificationType notificationType,
8184
commenterName
8285
);
8386

84-
sendAgitService.sendAgit(pushNotificationTemplate, task);
87+
if(notificationType.equals(NotificationType.TASK_REQUESTED)){
88+
Long agitPostId = sendAgitService.sendAgit(pushNotificationTemplate, task);
89+
90+
task.updateAgitPostId(agitPostId);
91+
taskService.upsert(task);
92+
}
8593
}
8694
}

0 commit comments

Comments
 (0)