Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,15 @@
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;
import lombok.RequiredArgsConstructor;

@Component
@RequiredArgsConstructor
public class PostApprovalNotificationTxListener {
public class PostNotificationTxListener {

private final RealTimeNotificationService realTimeNotificationService;
private final NotificationService notificationService;
Expand All @@ -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()
);
}
}
Original file line number Diff line number Diff line change
@@ -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) {
}
14 changes: 7 additions & 7 deletions src/main/java/kr/mywork/domain/post/service/ReviewService.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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());
Expand All @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down
Loading