diff --git a/be/src/main/java/yeonba/be/notification/service/NotificationService.java b/be/src/main/java/yeonba/be/notification/service/NotificationService.java index 420f4924..28d6bbe7 100644 --- a/be/src/main/java/yeonba/be/notification/service/NotificationService.java +++ b/be/src/main/java/yeonba/be/notification/service/NotificationService.java @@ -1,5 +1,7 @@ package yeonba.be.notification.service; +import java.util.Arrays; +import java.util.List; import java.util.Optional; import lombok.RequiredArgsConstructor; import org.springframework.data.domain.Page; @@ -16,6 +18,7 @@ import yeonba.be.notification.enums.NotificationType; import yeonba.be.notification.event.NotificationSendEvent; import yeonba.be.notification.repository.NotificationCommand; +import yeonba.be.notification.repository.NotificationPermissionCommand; import yeonba.be.notification.repository.NotificationPermissionQuery; import yeonba.be.notification.repository.NotificationQuery; import yeonba.be.user.entity.User; @@ -26,10 +29,12 @@ public class NotificationService { private final UserQuery userQuery; - private final NotificationCommand notificationCommand; private final NotificationQuery notificationQuery; private final NotificationPermissionQuery notificationPermissionQuery; + private final NotificationCommand notificationCommand; + private final NotificationPermissionCommand notificationPermissionCommand; + @Transactional public NotificationPageResponse getRecentlyReceivedNotificationsBy( long receiverId, NotificationPageRequest request) { @@ -67,6 +72,15 @@ public void saveNotification(NotificationSendEvent sendEvent) { notificationCommand.save(notification); } + public void saveAllowedNotificationPermissions(User user) { + + List notificationPermissions = + Arrays.stream(NotificationType.values()) + .map(type -> new NotificationPermission(type, user)) + .toList(); + notificationPermissionCommand.saveAll(notificationPermissions); + } + @Transactional(readOnly = true) public NotificationUnreadExistResponse isUnreadNotificationExist(long receiverId) {