diff --git a/baebae-BE/src/main/java/com/web/baebaeBE/domain/notification/service/NotificationService.java b/baebae-BE/src/main/java/com/web/baebaeBE/domain/notification/service/NotificationService.java index d74e5fdc..9474f839 100644 --- a/baebae-BE/src/main/java/com/web/baebaeBE/domain/notification/service/NotificationService.java +++ b/baebae-BE/src/main/java/com/web/baebaeBE/domain/notification/service/NotificationService.java @@ -13,6 +13,7 @@ import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; import java.time.LocalDateTime; import java.util.ArrayList; @@ -21,6 +22,7 @@ @Service @Slf4j @RequiredArgsConstructor +@Transactional public class NotificationService { private final NotificationRepository notificationRepository; @@ -45,14 +47,15 @@ public Notification createNotification(NotificationRequest.create createNotifica // 특정 멤버의 모든 알람 조회 + @Transactional public NotificationResponse.NotificationListResponse getNotificationsListByMember(Long memberId) { Member member = memberRepository.findById(memberId) .orElseThrow(() -> new BusinessException(LoginException.NOT_EXIST_MEMBER)); List notificationList = notificationRepository.findByMemberOrderByNotificationTimeDesc(member); - // 사용자에게 반환할 알림 목록을 복사 - List notificationsToReturn = new ArrayList<>(notificationList); + // 복사본을 사용하여 응답을 생성 + NotificationResponse.NotificationListResponse response = NotificationResponse.NotificationContentResponse.ListOf(new ArrayList<>(notificationList)); // 원본 알림 목록의 isChecked 필드를 true로 설정하고, 데이터베이스에 변경 사항을 저장 for (Notification notification : notificationList) { @@ -60,8 +63,7 @@ public NotificationResponse.NotificationListResponse getNotificationsListByMembe } notificationRepository.saveAll(notificationList); - // 복사한 알림 목록을 사용하여 응답을 생성 - return NotificationResponse.NotificationContentResponse.ListOf(notificationsToReturn); + return response; }