Skip to content

Commit

Permalink
Merge remote-tracking branch 'refs/remotes/origin/LF1-687-delivery-st…
Browse files Browse the repository at this point in the history
…atus-change-done' into LF1-687-delivery-status-change-done
  • Loading branch information
nowgnas committed Dec 15, 2023
2 parents 5ad2221 + 780a9bb commit f69a794
Show file tree
Hide file tree
Showing 7 changed files with 104 additions and 5 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ test {
"**/handler/**",
"**/common/**",
"**/api/**",
"**/emitter/**"
"**/emitter/**"
]
}
useJUnitPlatform()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -37,6 +38,7 @@ public void saveResaleNotification(NotificationData<ResaleNotificationList> rest
}

public void saveSingleNotification(PublishNotificationInformation publishInformation, Long id) {
notificationJpaRepository.save(getNotification(publishInformation, id));
Notification notification = getNotification(publishInformation, id);
notificationJpaRepository.save(notification);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
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.OrderCancelNotification;
import kr.bb.notification.domain.notification.infrastructure.dto.SettlementNotification;
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;
Expand Down Expand Up @@ -67,9 +69,21 @@ public void publishNewOrderNotification(NotificationData<NewOrderNotification> n
notification.getPublishInformation(), notification.getWhoToNotify().getStoreId());
}

public void publishOutOfStockNotification(
NotificationData<OutOfStockNotification> outOfStockNotification) {
NotificationInformation sseData =
NotificationInformation.getSSEData(
outOfStockNotification.getPublishInformation(),
outOfStockNotification.getWhoToNotify().getStoreId());
sse.publishCustomer(sseData);

notificationCommandService.saveSingleNotification(
outOfStockNotification.getPublishInformation(),
outOfStockNotification.getWhoToNotify().getStoreId());
}

public void publishDeliveryStartNotification(
NotificationData<DeliveryNotification> notificationData) {

NotificationInformation notifyData =
NotificationInformation.getDeliveryNotificationData(notificationData);
sse.publishCustomer(notifyData);
Expand All @@ -80,8 +94,20 @@ public void publishDeliveryStartNotification(
notificationData.getPublishInformation(), notificationData.getWhoToNotify().getUserId());
}

public void publishOrderCancelNotification(NotificationData<OrderCancelNotification> notification) {
NotificationInformation sseData = NotificationInformation.getSSEData(
public void publishSettlementNotification(NotificationData<SettlementNotification> notification) {
NotificationInformation sseData =
NotificationInformation.getSSEData(
notification.getPublishInformation(), notification.getWhoToNotify().getStoreId());
sse.publishCustomer(sseData);

notificationCommandService.saveSingleNotification(
notification.getPublishInformation(), notification.getWhoToNotify().getStoreId());
}

public void publishOrderCancelNotification(
NotificationData<OrderCancelNotification> notification) {
NotificationInformation sseData =
NotificationInformation.getSSEData(
notification.getPublishInformation(), notification.getWhoToNotify().getStoreId());
sse.publishCustomer(sseData);

Expand Down
Original file line number Diff line number Diff line change
@@ -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;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package kr.bb.notification.domain.notification.infrastructure.dto;

import lombok.Builder;
import lombok.Getter;

@Getter
@Builder
public class SettlementNotification {
// TODO: 정산 알림 가게 id를 어떻게 받을지 정의 필요
private Long storeId;
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
import java.util.Map;
import kr.bb.notification.domain.notification.helper.NotificationActionHelper;
import kr.bb.notification.domain.notification.infrastructure.dto.OrderCancelNotification;
import kr.bb.notification.domain.notification.infrastructure.dto.OutOfStockNotification;
import kr.bb.notification.domain.notification.infrastructure.dto.SettlementNotification;
import lombok.RequiredArgsConstructor;
import org.springframework.cloud.aws.messaging.listener.Acknowledgment;
import org.springframework.cloud.aws.messaging.listener.SqsMessageDeletionPolicy;
Expand Down Expand Up @@ -182,6 +184,48 @@ public void consumeDeliveryStartNotificationQueue(
ack.acknowledge();
}

@SqsListener(
value = "${cloud.aws.sqs.settlement-notification-queue.name}",
deletionPolicy = SqsMessageDeletionPolicy.NEVER)
public void consumeSettlementNotificationQueue(
@Payload String message, @Headers Map<String, String> headers, Acknowledgment ack)
throws JsonProcessingException {
NotificationData<SettlementNotification> settlement =
objectMapper.readValue(
message,
objectMapper
.getTypeFactory()
.constructParametricType(NotificationData.class, SettlementNotification.class));
NotificationData<SettlementNotification> notification =
NotificationData.notifyData(
settlement.getWhoToNotify(),
PublishNotificationInformation.updateRole(
settlement.getPublishInformation(), Role.MANAGER));
// call facade
notificationActionHelper.publishSettlementNotification(notification);
}

@SqsListener(
value = "${cloud.aws.sqs.out-of-stock-notification-queue.name}",
deletionPolicy = SqsMessageDeletionPolicy.NEVER)
public void consumeOutOfStockNotificationQueue(
@Payload String message, @Headers Map<String, String> headers, Acknowledgment ack)
throws JsonProcessingException {
NotificationData<OutOfStockNotification> outOfStock =
objectMapper.readValue(
message,
objectMapper
.getTypeFactory()
.constructParametricType(NotificationData.class, OutOfStockNotification.class));
NotificationData<OutOfStockNotification> notification =
NotificationData.notifyData(
outOfStock.getWhoToNotify(),
PublishNotificationInformation.updateRole(
outOfStock.getPublishInformation(), Role.MANAGER));
// call facade
notificationActionHelper.publishOutOfStockNotification(notification);
}

@SqsListener(
value = "${cloud.aws.sqs.order-cancel-notification-queue.name}",
deletionPolicy = SqsMessageDeletionPolicy.NEVER)
Expand Down
6 changes: 6 additions & 0 deletions src/test/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,12 @@ cloud:
delivery-status-update-notification-queue:
name: ""
url: ""
settlement-notification-queue:
name: ""
url: ""
out-of-stock-notification-queue:
name: ""
url: ""
order-cancel-notification-queue:
name: ""
url: ""

0 comments on commit f69a794

Please sign in to comment.