From 8553da693554ade6bf001580499440271e068bad Mon Sep 17 00:00:00 2001 From: nowgnas Date: Wed, 13 Dec 2023 20:42:25 +0900 Subject: [PATCH] =?UTF-8?q?:sparkles:=20LF1-690=20=EC=9E=AC=EA=B3=A0=20?= =?UTF-8?q?=EB=B6=80=EC=A1=B1=20=EC=95=8C=EB=A6=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../NotificationCommandService.java | 15 ++++++++++++--- .../helper/NotificationActionHelper.java | 18 ++++++++++++++++-- .../dto/OutOfStockNotification.java | 10 ++++++++++ .../message/NotificationSQSListener.java | 19 +++++++++++++++++++ src/test/resources/application.yml | 3 +++ 5 files changed, 60 insertions(+), 5 deletions(-) create mode 100644 src/main/java/kr/bb/notification/domain/notification/infrastructure/dto/OutOfStockNotification.java diff --git a/src/main/java/kr/bb/notification/domain/notification/application/NotificationCommandService.java b/src/main/java/kr/bb/notification/domain/notification/application/NotificationCommandService.java index 3d158a5..eb85081 100644 --- a/src/main/java/kr/bb/notification/domain/notification/application/NotificationCommandService.java +++ b/src/main/java/kr/bb/notification/domain/notification/application/NotificationCommandService.java @@ -8,6 +8,7 @@ import kr.bb.notification.domain.notification.entity.MemberNotificationCommand; import kr.bb.notification.domain.notification.entity.Notification; import kr.bb.notification.domain.notification.entity.NotificationCommand; +import kr.bb.notification.domain.notification.repository.MemberNotificationJpaRepository; import kr.bb.notification.domain.notification.repository.NotificationJpaRepository; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; @@ -18,12 +19,13 @@ @RequiredArgsConstructor public class NotificationCommandService { private final NotificationJpaRepository notificationJpaRepository; + private final MemberNotificationJpaRepository memberNotificationJpaRepository; private Notification getNotification(PublishNotificationInformation publishInformation, Long id) { Notification notification = NotificationCommand.toEntity(publishInformation); MemberNotification memberNotification = MemberNotificationCommand.toEntity(id, publishInformation.getRole(), notification); - notification.setMemberNotifications(List.of(memberNotification)); + // notification.setMemberNotifications(List.of(memberNotification)); return notification; } @@ -37,7 +39,14 @@ public void saveResaleNotification(NotificationData rest } public void saveSingleNotification(PublishNotificationInformation publishInformation, Long id) { - Notification notification = getNotification(publishInformation, id); - notificationJpaRepository.save(notification); + MemberNotification memberNotification = getMemberNotification(publishInformation, id); + memberNotificationJpaRepository.save(memberNotification); + // notificationJpaRepository.save(notification); + } + + private MemberNotification getMemberNotification( + PublishNotificationInformation publishInformation, Long id) { + Notification notification = NotificationCommand.toEntity(publishInformation); + return MemberNotificationCommand.toEntity(id, publishInformation.getRole(), notification); } } diff --git a/src/main/java/kr/bb/notification/domain/notification/helper/NotificationActionHelper.java b/src/main/java/kr/bb/notification/domain/notification/helper/NotificationActionHelper.java index 7b1b9a3..d2c60b0 100644 --- a/src/main/java/kr/bb/notification/domain/notification/helper/NotificationActionHelper.java +++ b/src/main/java/kr/bb/notification/domain/notification/helper/NotificationActionHelper.java @@ -8,11 +8,13 @@ import java.util.List; import kr.bb.notification.domain.notification.application.NotificationCommandService; import kr.bb.notification.domain.notification.entity.NotificationCommand.NotificationInformation; +import kr.bb.notification.domain.notification.infrastructure.dto.OutOfStockNotification; import kr.bb.notification.domain.notification.infrastructure.sms.SendSMS; import kr.bb.notification.domain.notification.infrastructure.sse.SendSSE; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Component; + @Slf4j @Component @RequiredArgsConstructor @@ -67,14 +69,26 @@ public void publishNewOrderNotification(NotificationData n public void publishDeliveryStartNotification( NotificationData notificationData) { - NotificationInformation notifyData = NotificationInformation.getDeliveryNotificationData(notificationData); sse.publishCustomer(notifyData); -// sms.publishCustomer(notifyData); + sms.publishCustomer(notifyData); // save notification notificationCommandService.saveSingleNotification( notificationData.getPublishInformation(), notificationData.getWhoToNotify().getUserId()); } + + public void publishOutOfStockNotification( + NotificationData outOfStockNotification) { + NotificationInformation sseData = + NotificationInformation.getSSEData( + outOfStockNotification.getPublishInformation(), + outOfStockNotification.getWhoToNotify().getStoreId()); + sse.publishCustomer(sseData); + + notificationCommandService.saveSingleNotification( + outOfStockNotification.getPublishInformation(), + outOfStockNotification.getWhoToNotify().getStoreId()); + } } diff --git a/src/main/java/kr/bb/notification/domain/notification/infrastructure/dto/OutOfStockNotification.java b/src/main/java/kr/bb/notification/domain/notification/infrastructure/dto/OutOfStockNotification.java new file mode 100644 index 0000000..d5c060a --- /dev/null +++ b/src/main/java/kr/bb/notification/domain/notification/infrastructure/dto/OutOfStockNotification.java @@ -0,0 +1,10 @@ +package kr.bb.notification.domain.notification.infrastructure.dto; + +import lombok.Builder; +import lombok.Getter; + +@Getter +@Builder +public class OutOfStockNotification { + private Long storeId; +} diff --git a/src/main/java/kr/bb/notification/domain/notification/infrastructure/message/NotificationSQSListener.java b/src/main/java/kr/bb/notification/domain/notification/infrastructure/message/NotificationSQSListener.java index 8c20547..9a6cdb6 100644 --- a/src/main/java/kr/bb/notification/domain/notification/infrastructure/message/NotificationSQSListener.java +++ b/src/main/java/kr/bb/notification/domain/notification/infrastructure/message/NotificationSQSListener.java @@ -11,6 +11,7 @@ import com.fasterxml.jackson.databind.ObjectMapper; import java.util.Map; import kr.bb.notification.domain.notification.helper.NotificationActionHelper; +import kr.bb.notification.domain.notification.infrastructure.dto.OutOfStockNotification; import lombok.RequiredArgsConstructor; import org.springframework.cloud.aws.messaging.listener.Acknowledgment; import org.springframework.cloud.aws.messaging.listener.SqsMessageDeletionPolicy; @@ -156,4 +157,22 @@ public void consumeDeliveryStartNotificationQueue( notificationFacadeHandler.publishDeliveryStartNotification(deliveryNotification); ack.acknowledge(); } + + @SqsListener( + value = "${cloud.aws.sqs.out-of-stock-notification-queue.name}", + deletionPolicy = SqsMessageDeletionPolicy.NEVER) + public void consumeOutOfStockNotificationQueue( + @Payload String message, @Headers Map headers, Acknowledgment ack) + throws JsonProcessingException { + NotificationData outOfStockNotification = + objectMapper.readValue( + message, + objectMapper + .getTypeFactory() + .constructParametricType(NotificationData.class, OutOfStockNotification.class)); + outOfStockNotification.getPublishInformation().setRole(Role.MANAGER); + // call facade + notificationFacadeHandler.publishOutOfStockNotification(outOfStockNotification); + ack.acknowledge(); + } } diff --git a/src/test/resources/application.yml b/src/test/resources/application.yml index fe6bf14..122d5bd 100644 --- a/src/test/resources/application.yml +++ b/src/test/resources/application.yml @@ -53,5 +53,8 @@ cloud: name: "" url: "" delivery-start-notification-queue: + name: "" + url: "" + out-of-stock-notification-queue: name: "" url: "" \ No newline at end of file