Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

reafactor: 알림 전송 관련 리팩토링 #111

Merged
merged 4 commits into from
Jun 7, 2024
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
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
import static com.example.sabujak.notification.entity.NotificationType.COMMUNITY;
import static com.example.sabujak.notification.entity.NotificationType.RESERVATION;
import static java.lang.Thread.currentThread;
import static org.springframework.core.Ordered.HIGHEST_PRECEDENCE;
import static org.springframework.transaction.event.TransactionPhase.AFTER_COMMIT;

@Slf4j
Expand All @@ -35,33 +34,37 @@ public class FCMNotificationEventListener {
@TransactionalEventListener(phase = AFTER_COMMIT)
@Async
public void saveAndSendFCMNotificationForComment(SaveCommentEvent event) {
String email = event.receiverEmail();
String email = event.writerEmail();
String content = event.notificationContent();
String targetUrl = event.targetUrl();
log.info("Preparing FCM Notification For Comment. " +
"Notification Recipient Email: [{}], Content: [{}], Target URL: [{}]", email, content, targetUrl);
saveNotification(DEFAULT_TITLE, content, targetUrl, COMMUNITY, event.recipient());
log.info("Start Preparing FCM Notification For Comment. " +
"Writer Email: [{}], Notification Content: [{}], Target URL: [{}]", email, content, targetUrl);
saveNotification(DEFAULT_TITLE, content, targetUrl, COMMUNITY, event.writer());
sendFCMNotification(email, createFCMMessage(email, DEFAULT_TITLE, content, targetUrl));
}

@TransactionalEventListener(phase = AFTER_COMMIT)
@Order(value = HIGHEST_PRECEDENCE)
@Order(1)
@Async
public void saveAndSendFCMNotificationForMeetingRoomInvitation(ReserveMeetingRoomEvent event) {
List<Member> participants = event.participants();
if (participants.isEmpty()) {
return;
}
String content = event.invitationContent();
String targetUrl = event.targetUrl();
log.info("Preparing FCM Notification For Meeting Room Invitation. " +
log.info("Start Preparing FCM Notification For Meeting Room Invitation. " +
"Notification Content: [{}], Target URL: [{}]", content, targetUrl);
for (Member participant : event.participants()) {
for (Member participant : participants) {
String email = participant.getMemberEmail();
log.info("Notification Recipient Email: [{}]", email);
log.info("Notification Target Participant Email: [{}]", email);
saveNotification(MEETING_ROOM_INVITATION_TITLE, content, targetUrl, RESERVATION, participant);
sendFCMNotificationAsync(email, createFCMMessage(email, MEETING_ROOM_INVITATION_TITLE, content, targetUrl));
}
}

@TransactionalEventListener(phase = AFTER_COMMIT)
@Order(value = HIGHEST_PRECEDENCE + 1)
@Order(2)
@Async
public void saveAndSendFCMNotificationForRechargingRoomCancellation(ReserveMeetingRoomEvent event) {
List<Member> cancelers = event.cancelers();
Expand All @@ -70,11 +73,11 @@ public void saveAndSendFCMNotificationForRechargingRoomCancellation(ReserveMeeti
}
String content = event.cancellationContent();
String targetUrl = event.targetUrl();
log.info("Preparing FCM Notification For Recharging Room Cancellation " +
log.info("Start Preparing FCM Notification For Recharging Room Cancellation. " +
"Notification Content: [{}], Target URL: [{}]", content, targetUrl);
for (Member canceler : cancelers) {
String email = canceler.getMemberEmail();
log.info("Notification Canceler Email: [{}]", email);
log.info("Notification Target Canceler Email: [{}]", email);
saveNotification(RECHARGING_ROOM_CANCELLATION_TITLE, content, targetUrl, RESERVATION, canceler);
sendFCMNotificationAsync(email, createFCMMessage(email, RECHARGING_ROOM_CANCELLATION_TITLE, content, targetUrl));
}
Expand All @@ -84,12 +87,12 @@ public void saveAndSendFCMNotificationForRechargingRoomCancellation(ReserveMeeti
public void saveAndSendFCMNotificationForMeetingRoomEntry(FindMeetingRoomEntryNotificationMembersEvent event) {
String content = event.content();
String targetUrl = event.targetUrl();
log.info("Preparing FCM Notification For Meeting Room Entry. " +
log.info("Start Preparing FCM Notification For Meeting Room Entry. " +
"Notification Content: [{}], Target URL: [{}]", content, targetUrl);
for (Member recipient : event.recipients()) {
String email = recipient.getMemberEmail();
log.info("Notification Recipient Email: [{}]", email);
saveNotification(MEETING_ROOM_RESERVATION_TITLE, content, targetUrl, RESERVATION, recipient);
for (Member member : event.members()) {
String email = member.getMemberEmail();
log.info("Notification Target Member Email: [{}]", email);
saveNotification(MEETING_ROOM_RESERVATION_TITLE, content, targetUrl, RESERVATION, member);
sendFCMNotificationAsync(email, createFCMMessage(email, MEETING_ROOM_RESERVATION_TITLE, content, targetUrl));
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
public record SaveCommentEvent(
String targetUrl,
String notificationContent,
String receiverEmail,
Member recipient
String writerEmail,
Member writer
) {
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@
public record FindMeetingRoomEntryNotificationMembersEvent(
String targetUrl,
String content,
List<Member> recipients
List<Member> members
) {
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
import java.time.Instant;
import java.time.LocalDateTime;

import static org.springframework.core.Ordered.HIGHEST_PRECEDENCE;
import static org.springframework.transaction.event.TransactionPhase.AFTER_COMMIT;

@Slf4j
Expand All @@ -25,7 +24,7 @@ public class ReservationNotificationScheduleEventListener {
private final ReservationService reservationService;

@TransactionalEventListener(phase = AFTER_COMMIT)
@Order(value = HIGHEST_PRECEDENCE + 2)
@Order(3)
public void addMeetingRoomEntryNotificationSchedule(ReserveMeetingRoomEvent event) {
Long reservationId = event.reservationId();
LocalDateTime notificationTime = event.reservationDate().minusMinutes(30);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
import static com.example.sabujak.security.exception.AuthErrorCode.ACCOUNT_NOT_EXISTS;
import static com.example.sabujak.space.exception.meetingroom.SpaceErrorCode.FOCUS_DESK_NOT_FOUND;
import static com.example.sabujak.space.exception.meetingroom.SpaceErrorCode.MEETING_ROOM_NOT_FOUND;
import static org.springframework.transaction.annotation.Propagation.REQUIRED;

@Slf4j
@Service
Expand Down Expand Up @@ -433,7 +434,7 @@ private ReserveMeetingRoomEvent createReserveMeetingRoomEvent(Reservation reserv
return new ReserveMeetingRoomEvent(reservationId, reservationDate, "", invitationContent, cancellationContent, reservationContent, participants, cancelers);
}

@Transactional
@Transactional(propagation = REQUIRED)
@Async
public void findMeetingRoomEntryNotificationMembers(Long reservationId, String targetUrl, String content) {
log.info("Start Finding Members To Send Meeting Room Entry Notification.");
Expand Down
Loading