diff --git a/src/main/java/kr/mywork/domain/notification/listener/event/NotificationCreateEvent.java b/src/main/java/kr/mywork/domain/notification/listener/event/NotificationCreateEvent.java deleted file mode 100644 index 03005fbc..00000000 --- a/src/main/java/kr/mywork/domain/notification/listener/event/NotificationCreateEvent.java +++ /dev/null @@ -1,12 +0,0 @@ -package kr.mywork.domain.notification.listener.event; - -import java.time.LocalDateTime; -import java.util.UUID; - -import kr.mywork.domain.notification.model.NotificationActionType; -import kr.mywork.domain.notification.model.TargetType; - -public record NotificationCreateEvent(UUID authorId, String authorName, String content, String actorName, UUID actorId, - TargetType targetType, UUID targetId, NotificationActionType notificationActionType, - LocalDateTime modifiedAt, UUID projectId, UUID projectStepId) { -} diff --git a/src/main/java/kr/mywork/domain/notification/listener/event/NotificationTxEventListener.java b/src/main/java/kr/mywork/domain/notification/listener/event/NotificationTxEventListener.java deleted file mode 100644 index c69ab3ad..00000000 --- a/src/main/java/kr/mywork/domain/notification/listener/event/NotificationTxEventListener.java +++ /dev/null @@ -1,47 +0,0 @@ -package kr.mywork.domain.notification.listener.event; - -import org.springframework.scheduling.annotation.Async; -import org.springframework.stereotype.Component; -import org.springframework.transaction.annotation.Propagation; -import org.springframework.transaction.annotation.Transactional; -import org.springframework.transaction.event.TransactionPhase; -import org.springframework.transaction.event.TransactionalEventListener; - -import kr.mywork.domain.notification.service.NotificationService; -import kr.mywork.domain.notification.service.RealTimeNotificationService; -import lombok.RequiredArgsConstructor; -import lombok.extern.slf4j.Slf4j; - -@Slf4j -@Component -@RequiredArgsConstructor -public class NotificationTxEventListener { - - private final RealTimeNotificationService realTimeNotificationService; - private final NotificationService notificationService; - - @Async(value = "eventTaskExecutor") - @Transactional(propagation = Propagation.REQUIRES_NEW) - @TransactionalEventListener(phase = TransactionPhase.AFTER_COMMIT) - public void handleNotificationCreateEvent(final NotificationCreateEvent event) { - long unreadCount = notificationService.countUnreadNotifications(event.authorId()); - realTimeNotificationService.sendNotification(event.authorId(), "notification-unread-count", unreadCount); - saveNotification(event); - } - - private void saveNotification(final NotificationCreateEvent event) { - notificationService.save( - event.authorId(), - event.authorName(), - event.content(), - event.actorName(), - event.actorId(), - event.targetType(), - event.targetId(), - event.notificationActionType(), - event.modifiedAt(), - event.projectId(), - event.projectStepId() - ); - } -} diff --git a/src/main/java/kr/mywork/domain/post/listener/PostApprovalNotificationTxListener.java b/src/main/java/kr/mywork/domain/post/listener/PostNotificationTxListener.java similarity index 58% rename from src/main/java/kr/mywork/domain/post/listener/PostApprovalNotificationTxListener.java rename to src/main/java/kr/mywork/domain/post/listener/PostNotificationTxListener.java index cc9975df..89dd1716 100644 --- a/src/main/java/kr/mywork/domain/post/listener/PostApprovalNotificationTxListener.java +++ b/src/main/java/kr/mywork/domain/post/listener/PostNotificationTxListener.java @@ -7,6 +7,7 @@ import org.springframework.transaction.event.TransactionPhase; import org.springframework.transaction.event.TransactionalEventListener; +import kr.mywork.domain.post.listener.event.ReviewNotificationCreateEvent; import kr.mywork.domain.notification.service.NotificationService; import kr.mywork.domain.notification.service.RealTimeNotificationService; import kr.mywork.domain.post.listener.event.PostApprovalNotificationEvent; @@ -14,7 +15,7 @@ @Component @RequiredArgsConstructor -public class PostApprovalNotificationTxListener { +public class PostNotificationTxListener { private final RealTimeNotificationService realTimeNotificationService; private final NotificationService notificationService; @@ -23,15 +24,40 @@ public class PostApprovalNotificationTxListener { @Async("eventTaskExecutor") @TransactionalEventListener(phase = TransactionPhase.AFTER_COMMIT) public void handlePostApprovalAlarmEvent(final PostApprovalNotificationEvent event) { + saveApprovalNotification(event); final long unreadCount = notificationService.countUnreadNotifications(event.authorId()); realTimeNotificationService.sendNotification(event.authorId(), "notification-unread-count", unreadCount); - saveNotification(event); } - private void saveNotification(final PostApprovalNotificationEvent event) { + private void saveApprovalNotification(final PostApprovalNotificationEvent event) { notificationService.save( event.authorId(), event.authorName(), event.postTitle(), event.actorName(), event.actorId(), event.targetType(), event.postId(), event.notificationActionType(), event.modifiedAt(), event.projectId(), event.projectStepId()); } + + @Async(value = "eventTaskExecutor") + @Transactional(propagation = Propagation.REQUIRES_NEW) + @TransactionalEventListener(phase = TransactionPhase.AFTER_COMMIT) + public void handleNotificationCreateEvent(final ReviewNotificationCreateEvent event) { + saveReviewNotification(event); + long unreadCount = notificationService.countUnreadNotifications(event.authorId()); + realTimeNotificationService.sendNotification(event.authorId(), "notification-unread-count", unreadCount); + } + + private void saveReviewNotification(final ReviewNotificationCreateEvent event) { + notificationService.save( + event.authorId(), + event.authorName(), + event.content(), + event.actorName(), + event.actorId(), + event.targetType(), + event.targetId(), + event.notificationActionType(), + event.modifiedAt(), + event.projectId(), + event.projectStepId() + ); + } } diff --git a/src/main/java/kr/mywork/domain/post/listener/event/ReviewNotificationCreateEvent.java b/src/main/java/kr/mywork/domain/post/listener/event/ReviewNotificationCreateEvent.java new file mode 100644 index 00000000..109e885b --- /dev/null +++ b/src/main/java/kr/mywork/domain/post/listener/event/ReviewNotificationCreateEvent.java @@ -0,0 +1,12 @@ +package kr.mywork.domain.post.listener.event; + +import java.time.LocalDateTime; +import java.util.UUID; + +import kr.mywork.domain.notification.model.NotificationActionType; +import kr.mywork.domain.notification.model.TargetType; + +public record ReviewNotificationCreateEvent(UUID authorId, String authorName, String content, String actorName, UUID actorId, + TargetType targetType, UUID targetId, NotificationActionType notificationActionType, + LocalDateTime modifiedAt, UUID projectId, UUID projectStepId) { +} diff --git a/src/main/java/kr/mywork/domain/post/service/ReviewService.java b/src/main/java/kr/mywork/domain/post/service/ReviewService.java index 33b9a309..c2af61b5 100644 --- a/src/main/java/kr/mywork/domain/post/service/ReviewService.java +++ b/src/main/java/kr/mywork/domain/post/service/ReviewService.java @@ -16,7 +16,7 @@ import kr.mywork.domain.activityLog.listener.eventObject.ActivityLogCreateEvent; import kr.mywork.domain.activityLog.listener.eventObject.ActivityLogDeleteEvent; import kr.mywork.domain.activityLog.listener.eventObject.ActivityModifyEvent; -import kr.mywork.domain.notification.listener.event.NotificationCreateEvent; +import kr.mywork.domain.post.listener.event.ReviewNotificationCreateEvent; import kr.mywork.domain.notification.model.NotificationActionType; import kr.mywork.domain.notification.model.TargetType; import kr.mywork.domain.post.errors.PostErrorType; @@ -66,20 +66,20 @@ public ReviewCreateResponse save(final ReviewCreateRequest reviewCreateRequest, .orElseThrow(() -> new ProjectStepNotFoundException(ProjectStepErrorType.PROJECT_STEP_NOT_FOUND)); final UUID memberId = loginMemberDetail.memberId(); - final NotificationCreateEvent notificationCreateEvent = createNotificationCreateEvent( + final ReviewNotificationCreateEvent reviewNotificationCreateEvent = createNotificationCreateEvent( loginMemberDetail, post, projectStep); if (!post.isAuthor(memberId)) { - sendNotificationCreateEvent(notificationCreateEvent); + sendReviewNotificationCreateEvent(reviewNotificationCreateEvent); } sendActivityLogCreateEvent(loginMemberDetail, savedReview); return ReviewCreateResponse.fromEntity(savedReview); } - private NotificationCreateEvent createNotificationCreateEvent(final LoginMemberDetail loginMemberDetail, + private ReviewNotificationCreateEvent createNotificationCreateEvent(final LoginMemberDetail loginMemberDetail, final Post post, final ProjectStep projectStep) { - return new NotificationCreateEvent( + return new ReviewNotificationCreateEvent( post.getAuthorId(), post.getAuthorName(), post.getTitle(), loginMemberDetail.memberName(), loginMemberDetail.memberId(), TargetType.POST, post.getId(), NotificationActionType.REVIEW, LocalDateTime.now(), projectStep.getProjectId(), projectStep.getId()); @@ -89,8 +89,8 @@ private void sendActivityLogCreateEvent(final LoginMemberDetail loginMemberDetai eventPublisher.publishEvent(new ActivityLogCreateEvent(savedReview, loginMemberDetail)); } - private void sendNotificationCreateEvent(final NotificationCreateEvent notificationCreateEvent) { - eventPublisher.publishEvent(notificationCreateEvent); + private void sendReviewNotificationCreateEvent(final ReviewNotificationCreateEvent reviewNotificationCreateEvent) { + eventPublisher.publishEvent(reviewNotificationCreateEvent); } public ReviewModifyResponse modifyComment(final ReviewModifyRequest reviewModifyRequest, diff --git a/src/main/java/kr/mywork/domain/project_checklist/listener/CheckListNotificationTxListener.java b/src/main/java/kr/mywork/domain/project_checklist/listener/CheckListNotificationTxListener.java index d2bbb14f..bda720d4 100644 --- a/src/main/java/kr/mywork/domain/project_checklist/listener/CheckListNotificationTxListener.java +++ b/src/main/java/kr/mywork/domain/project_checklist/listener/CheckListNotificationTxListener.java @@ -23,12 +23,12 @@ public class CheckListNotificationTxListener { @TransactionalEventListener(phase = TransactionPhase.AFTER_COMMIT) @Transactional(propagation = Propagation.REQUIRES_NEW) public void handleCheckListCreatedHistory(final CheckListApprovalNotificationEvent event) { + saveCheckListNotification(event); final long unreadCount = notificationService.countUnreadNotifications(event.authorId()); realTimeNotificationService.sendNotification(event.authorId(), "notification-unread-count", unreadCount); - saveNotification(event); } - private void saveNotification(final CheckListApprovalNotificationEvent event) { + private void saveCheckListNotification(final CheckListApprovalNotificationEvent event) { notificationService.save( event.authorId(), event.authorName(),