Skip to content

Commit

Permalink
Merge pull request #14 from nowgnas/LF1-690-out-of-stock-notification
Browse files Browse the repository at this point in the history
✨ LF1-690 재고 부족 알림
  • Loading branch information
JIUNG9 authored Dec 14, 2023
2 parents 8ec7876 + 6a394cd commit 862071e
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 7 deletions.
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 All @@ -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;
}

Expand All @@ -37,7 +39,14 @@ public void saveResaleNotification(NotificationData<ResaleNotificationList> 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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
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.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 @@ -69,19 +70,33 @@ public void publishNewOrderNotification(NotificationData<NewOrderNotification> n

public void publishDeliveryStartNotification(
NotificationData<DeliveryNotification> 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 publishOrderCancelNotification(NotificationData<OrderCancelNotification> notification) {
NotificationInformation sseData = NotificationInformation.getSSEData(
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 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
Expand Up @@ -12,6 +12,7 @@
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 lombok.RequiredArgsConstructor;
import org.springframework.cloud.aws.messaging.listener.Acknowledgment;
import org.springframework.cloud.aws.messaging.listener.SqsMessageDeletionPolicy;
Expand Down Expand Up @@ -158,6 +159,23 @@ public void consumeDeliveryStartNotificationQueue(
ack.acknowledge();
}

@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> outOfStockNotification =
objectMapper.readValue(
message,
objectMapper
.getTypeFactory()
.constructParametricType(NotificationData.class, OutOfStockNotification.class));
outOfStockNotification.getPublishInformation().setRole(Role.MANAGER);
// call facade
notificationFacadeHandler.publishOutOfStockNotification(outOfStockNotification);
}

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

0 comments on commit 862071e

Please sign in to comment.