Skip to content

Commit

Permalink
Merge pull request #13 from nowgnas/LF1-684-delivery-start-notification
Browse files Browse the repository at this point in the history
Lf1 684 delivery start notification 기능 구현
  • Loading branch information
qwerty1434 authored Dec 13, 2023
2 parents 1c0dcf4 + b28019e commit 91bb367
Show file tree
Hide file tree
Showing 18 changed files with 141 additions and 92 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ dependencies {
implementation 'org.springframework.cloud:spring-cloud-aws-messaging:2.2.4.RELEASE'
implementation 'org.springframework.kafka:spring-kafka'
implementation 'software.amazon.awssdk:sns:2.21.37'
implementation 'io.github.lotteon-maven:blooming-blooms-utils:202312121054'
implementation 'io.github.lotteon-maven:blooming-blooms-utils:202312121629'

testImplementation 'org.mockito:mockito-core:4.8.0'

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package kr.bb.notification.domain.emitter.api;

import bloomingblooms.domain.notification.Role;
import kr.bb.notification.domain.emitter.application.SseService;
import lombok.RequiredArgsConstructor;
import org.springframework.http.MediaType;
Expand All @@ -16,16 +17,16 @@ public class SSERestController {
// TODO: 화면 테스트용으로 pathvariable 사용
@GetMapping(value = "subscribe/manager/{userId}", produces = MediaType.TEXT_EVENT_STREAM_VALUE)
public SseEmitter subscribeManager(@PathVariable Long userId) {
return sseService.subscribe(userId, "admin");
return sseService.subscribe(userId, Role.MANAGER.getRole());
}

@GetMapping(value = "subscribe/admin/{userId}", produces = MediaType.TEXT_EVENT_STREAM_VALUE)
public SseEmitter subscribeAdmin(@PathVariable Long userId) {
return sseService.subscribe(userId, "admin");
return sseService.subscribe(userId, Role.ADMIN.getRole());
}

@GetMapping(value = "subscribe/customer/{userId}", produces = MediaType.TEXT_EVENT_STREAM_VALUE)
public SseEmitter subscribe(@PathVariable Long userId) {
return sseService.subscribe(userId, "customer");
return sseService.subscribe(userId, Role.CUSTOMER.getRole());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ public void notify(NotificationInformation event) {

private void sendToClient(NotificationInformation event) {
String id = event.getRole().getRole() + event.getId();
log.info("ID IS " + id);
SseEmitter emitter = emitterRepository.get(event.getId(), event.getRole().getRole());
if (emitter != null) {
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import bloomingblooms.response.CommonResponse;
import kr.bb.notification.domain.notification.entity.NotificationCommand;
import kr.bb.notification.domain.notification.facade.NotificationQueryFacadeHandler;
import kr.bb.notification.domain.notification.helper.NotificationQueryActionHelper;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestHeader;
Expand All @@ -11,7 +11,7 @@
@RestController
@RequiredArgsConstructor
public class NotificationQueryController {
private final NotificationQueryFacadeHandler notificationQueryFacadeHandler;
private final NotificationQueryActionHelper notificationQueryFacadeHandler;

@GetMapping("unread-notification")
public CommonResponse<NotificationCommand.UnreadNotificationCount> getUnreadNotificationCount(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import bloomingblooms.response.CommonResponse;
import kr.bb.notification.domain.notification.entity.NotificationCommand;
import kr.bb.notification.domain.notification.facade.NotificationQueryFacadeHandler;
import kr.bb.notification.domain.notification.helper.NotificationQueryActionHelper;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestHeader;
Expand All @@ -11,7 +11,7 @@
@RestController
@RequiredArgsConstructor
public class NotificationQueryRestController {
private final NotificationQueryFacadeHandler notificationQueryFacadeHandler;
private final NotificationQueryActionHelper notificationQueryFacadeHandler;

@GetMapping("/")
public CommonResponse<NotificationCommand.NotificationList> getNotifications(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import bloomingblooms.domain.notification.NotificationData;
import bloomingblooms.domain.notification.PublishNotificationInformation;
import bloomingblooms.domain.notification.Role;
import bloomingblooms.domain.resale.ResaleNotificationList;
import java.util.List;
import kr.bb.notification.domain.notification.entity.MemberNotification;
Expand All @@ -20,30 +19,25 @@
public class NotificationCommandService {
private final NotificationJpaRepository notificationJpaRepository;

private Notification getNotification(
PublishNotificationInformation publishInformation, Long id, Role role) {
private Notification getNotification(PublishNotificationInformation publishInformation, Long id) {
Notification notification = NotificationCommand.toEntity(publishInformation);
MemberNotification memberNotification = MemberNotificationCommand.toEntity(id, role);
notification.getMemberNotifications().add(memberNotification);
MemberNotification memberNotification =
MemberNotificationCommand.toEntity(id, publishInformation.getRole(), notification);
notification.setMemberNotifications(List.of(memberNotification));
return notification;
}

public void saveResaleNotification(NotificationData<ResaleNotificationList> restoreNotification) {
Notification notification =
NotificationCommand.toEntity(restoreNotification.getPublishInformation());
List<MemberNotification> memberNotifications =
MemberNotificationCommand.toEntityList(restoreNotification.getWhoToNotify());
MemberNotificationCommand.toEntityList(restoreNotification.getWhoToNotify(), notification);
notification.getMemberNotifications().addAll(memberNotifications);
notificationJpaRepository.save(notification);
}

public void saveManagerNotification(
PublishNotificationInformation publishNotificationInformation, Long id) {
notificationJpaRepository.save(
getNotification(publishNotificationInformation, id, Role.MANAGER));
}

public void saveNewcomerNotification(PublishNotificationInformation publishInformation, Long id) {
notificationJpaRepository.save(getNotification(publishInformation, id, Role.ADMIN));
public void saveSingleNotification(PublishNotificationInformation publishInformation, Long id) {
Notification notification = getNotification(publishInformation, id);
notificationJpaRepository.save(notification);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
Expand Down Expand Up @@ -35,6 +37,7 @@ public class MemberNotification extends BaseEntity {
@Column(name = "user_id")
private Long userId;

@Enumerated(EnumType.STRING)
@Column(name = "role")
private Role role;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,23 @@
import bloomingblooms.domain.resale.ResaleNotificationList;
import java.util.List;
import java.util.stream.Collectors;
import kr.bb.notification.domain.notification.infrastructure.dto.NewOrderNotification;

public class MemberNotificationCommand {

public static List<MemberNotification> toEntityList(ResaleNotificationList whoToNotify) {
public static List<MemberNotification> toEntityList(
ResaleNotificationList whoToNotify, Notification notification) {
return whoToNotify.getResaleNotificationData().stream()
.map(item -> MemberNotification.builder().userId(item.getUserId()).build())
.map(
item ->
MemberNotification.builder()
.notification(notification)
.userId(item.getUserId())
.role(Role.CUSTOMER)
.build())
.collect(Collectors.toList());
}

public static MemberNotification toEntity(Long id, Role role) {
return MemberNotification.builder().userId(id).role(role).build();
public static MemberNotification toEntity(Long id, Role role, Notification notification) {
return MemberNotification.builder().userId(id).role(role).notification(notification).build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import bloomingblooms.domain.notification.NotificationKind;
import bloomingblooms.domain.notification.PublishNotificationInformation;
import bloomingblooms.domain.notification.Role;
import bloomingblooms.domain.notification.delivery.DeliveryNotification;
import bloomingblooms.domain.resale.ResaleNotificationList;
import java.util.List;
import java.util.stream.Collectors;
Expand Down Expand Up @@ -95,7 +96,7 @@ public static List<NotificationInformation> getResaleNotificationData(
.getNotificationKind()
.getMessage())
.phoneNumber(item.getPhoneNumber())
.role(restoreNotification.getRole())
.role(restoreNotification.getPublishInformation().getRole())
.notificationKind(
restoreNotification.getPublishInformation().getNotificationKind())
.redirectUrl(restoreNotification.getPublishInformation().getNotificationUrl())
Expand All @@ -113,5 +114,17 @@ public static NotificationInformation getSSEData(
.content(publishNotificationInformation.getNotificationKind().getMessage())
.build();
}

public static NotificationInformation getDeliveryNotificationData(
NotificationData<DeliveryNotification> notificationData) {
return NotificationInformation.builder()
.role(notificationData.getPublishInformation().getRole())
.phoneNumber(notificationData.getWhoToNotify().getPhoneNumber())
.content(notificationData.getPublishInformation().getNotificationKind().getMessage())
.redirectUrl(notificationData.getPublishInformation().getNotificationUrl())
.id(notificationData.getWhoToNotify().getUserId())
.notificationKind(notificationData.getPublishInformation().getNotificationKind())
.build();
}
}
}
Original file line number Diff line number Diff line change
@@ -1,20 +1,22 @@
package kr.bb.notification.domain.notification.facade;
package kr.bb.notification.domain.notification.helper;

import bloomingblooms.domain.notification.NotificationData;
import bloomingblooms.domain.notification.delivery.DeliveryNotification;
import bloomingblooms.domain.notification.neworder.NewOrderNotification;
import bloomingblooms.domain.notification.question.QuestionRegister;
import bloomingblooms.domain.resale.ResaleNotificationList;
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.NewOrderNotification;
import kr.bb.notification.domain.notification.infrastructure.dto.QuestionRegister;
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
public class NotificationFacadeHandler {
public class NotificationActionHelper {
private final SendSMS sms;
private final SendSSE sse;
private final NotificationCommandService notificationCommandService;
Expand All @@ -39,7 +41,7 @@ public void publishQuestionRegisterNotification(NotificationData<QuestionRegiste
sse.publishCustomer(sseNotification);

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

Expand All @@ -49,7 +51,7 @@ public void publishNewComerNotification(NotificationData<Void> notification) {
sse.publishCustomer(sseNotification);

// save notification
notificationCommandService.saveNewcomerNotification(notification.getPublishInformation(), 1L);
notificationCommandService.saveSingleNotification(notification.getPublishInformation(), 1L);
}

public void publishNewOrderNotification(NotificationData<NewOrderNotification> notification) {
Expand All @@ -59,7 +61,20 @@ public void publishNewOrderNotification(NotificationData<NewOrderNotification> n
sse.publishCustomer(sseNotification);

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

public void publishDeliveryStartNotification(
NotificationData<DeliveryNotification> notificationData) {

NotificationInformation notifyData =
NotificationInformation.getDeliveryNotificationData(notificationData);
sse.publishCustomer(notifyData);
// sms.publishCustomer(notifyData);

// save notification
notificationCommandService.saveSingleNotification(
notificationData.getPublishInformation(), notificationData.getWhoToNotify().getUserId());
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package kr.bb.notification.domain.notification.facade;
package kr.bb.notification.domain.notification.helper;

import kr.bb.notification.domain.notification.application.NotificationQueryService;
import kr.bb.notification.domain.notification.entity.NotificationCommand;
Expand All @@ -7,7 +7,7 @@

@Component
@RequiredArgsConstructor
public class NotificationQueryFacadeHandler {
public class NotificationQueryActionHelper {
private final NotificationQueryService notificationQueryService;

public NotificationCommand.NotificationList getNotifications(Long userId) {
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Loading

0 comments on commit 91bb367

Please sign in to comment.