feat(order, notification, kafka): 주문 상태 변경 시 kafka 메시지 발송
This commit is contained in:
@@ -34,6 +34,17 @@ public class NotificationConsumer {
|
||||
notificationService.insertOrderPlaced(kafkaSendOrderDto.getUserId(), kafkaSendOrderDto.getStoreId());
|
||||
}
|
||||
|
||||
@Transactional
|
||||
@KafkaListener(topics = "orderAccepted")
|
||||
public void orderAccepted(String kafkaMessage) throws JsonProcessingException {
|
||||
log.debug("## NotificationConsumer.orderAccepted");
|
||||
log.debug("#### kafka Message = {}", kafkaMessage);
|
||||
|
||||
KafkaSendOrderDto orderDto = objectMapper.readValue(kafkaMessage, KafkaSendOrderDto.class);
|
||||
|
||||
notificationService.insertOrderAccepted(orderDto.userId, orderDto.storeId);
|
||||
}
|
||||
|
||||
@Data @NoArgsConstructor
|
||||
static class KafkaSendOrderDto {
|
||||
private Long id;
|
||||
|
||||
@@ -11,4 +11,5 @@ public interface NotificationService {
|
||||
void updateNotification(UpdateNotificationDto dto);
|
||||
Long findNotificationCounts(Long userId, Yn readYn);
|
||||
void insertOrderPlaced(Long userId, Long storeId);
|
||||
void insertOrderAccepted(Long userId, Long storeId);
|
||||
}
|
||||
|
||||
@@ -59,9 +59,22 @@ public class NotificationServiceImpl implements NotificationService {
|
||||
GetStoreResponse storeResponse = storeClient.getStore(String.valueOf(storeId)).getData();
|
||||
|
||||
String title = "주문이 신청되었어요.";
|
||||
String storeName = "[" + storeResponse.getName() + "]";
|
||||
String storeName = "[" + storeResponse.getName() + "] ";
|
||||
String message = storeName + "매장의 주문이 신청되었습니다.";
|
||||
Notification notification = Notification.of(userId, message, title);
|
||||
notificationRepository.save(notification);
|
||||
}
|
||||
|
||||
@Transactional
|
||||
@Override
|
||||
public void insertOrderAccepted(Long userId, Long storeId) {
|
||||
GetStoreResponse storeInfo = storeClient.getStore(String.valueOf(storeId)).getData();
|
||||
|
||||
String title = "주문이 수락되었어요.";
|
||||
String storeName = "[" + storeInfo.getName() + "] ";
|
||||
String message = storeName + "매장의 주문이 수락되었습니다.";
|
||||
Notification notification = Notification.of(userId, message, title);
|
||||
notificationRepository.save(notification);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user