Skip to content

Commit

Permalink
refactor : NotificationEventListener에서 Notification 타입에 따라서 메서드를 생성하는…
Browse files Browse the repository at this point in the history
…게 아닌 하나로 추상화

#663
  • Loading branch information
java-saeng committed Oct 1, 2023
1 parent b91aadf commit 303e7ef
Showing 1 changed file with 8 additions and 33 deletions.
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
package com.emmsale.notification.application;

import com.emmsale.event_publisher.CommentNotificationEvent;
import com.emmsale.event_publisher.EventNotificationEvent;
import com.emmsale.event_publisher.MessageNotificationEvent;
import com.emmsale.event_publisher.NotificationEvent;
import com.emmsale.event_publisher.UpdateNotificationEvent;
import com.emmsale.notification.domain.Notification;
import com.emmsale.notification.domain.NotificationRepository;
Expand Down Expand Up @@ -51,47 +50,23 @@ public void createUpdateNotification(final UpdateNotificationEvent updateNotific

@Transactional(propagation = Propagation.REQUIRES_NEW)
@TransactionalEventListener
public void createCommentNotification(final CommentNotificationEvent commentNotificationEvent) {
public void createNotification(final NotificationEvent notificationEvent) {
try {
final String jsonData = objectMapper.writeValueAsString(commentNotificationEvent);
final String jsonData = objectMapper.writeValueAsString(notificationEvent);

final Notification notification = notificationRepository.save(
new Notification(
NotificationType.COMMENT, commentNotificationEvent.getReceiverId(),
commentNotificationEvent.getRedirectId(), commentNotificationEvent.getCreatedAt(),
NotificationType.valueOf(notificationEvent.getNotificationType()),
notificationEvent.getReceiverId(),
notificationEvent.getRedirectId(),
notificationEvent.getCreatedAt(),
jsonData
)
);

firebaseCloudMessageClient.sendMessageTo(
notification,
commentNotificationEvent.getReceiverId()
);

} catch (JsonProcessingException e) {
log.error("json 에러");
} catch (Exception e) {
log.error("파이어베이스 관련 에러, 알림 재요청 필요, {}", e.getMessage(), e);
}
}

@Transactional(propagation = Propagation.REQUIRES_NEW)
@TransactionalEventListener
public void createEventNotification(final EventNotificationEvent eventNotificationEvent) {
try {
final String jsonData = objectMapper.writeValueAsString(eventNotificationEvent);

final Notification notification = notificationRepository.save(
new Notification(
NotificationType.EVENT, eventNotificationEvent.getReceiverId(),
eventNotificationEvent.getRedirectId(), eventNotificationEvent.getCreatedAt(),
jsonData
)
);

firebaseCloudMessageClient.sendMessageTo(
notification,
eventNotificationEvent.getReceiverId()
notification.getReceiverId()
);

} catch (JsonProcessingException e) {
Expand Down

0 comments on commit 303e7ef

Please sign in to comment.