Skip to content

Commit

Permalink
hotfix: 알림조회 읽음처리 오류 해결
Browse files Browse the repository at this point in the history
  • Loading branch information
tioon committed May 20, 2024
1 parent 00edbc7 commit 489d59c
Showing 1 changed file with 6 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -21,6 +22,7 @@
@Service
@Slf4j
@RequiredArgsConstructor
@Transactional
public class NotificationService {

private final NotificationRepository notificationRepository;
Expand All @@ -45,23 +47,23 @@ 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<Notification> notificationList = notificationRepository.findByMemberOrderByNotificationTimeDesc(member);

// 사용자에게 반환할 알림 목록을 복사
List<Notification> notificationsToReturn = new ArrayList<>(notificationList);
// 복사본을 사용하여 응답을 생성
NotificationResponse.NotificationListResponse response = NotificationResponse.NotificationContentResponse.ListOf(new ArrayList<>(notificationList));

// 원본 알림 목록의 isChecked 필드를 true로 설정하고, 데이터베이스에 변경 사항을 저장
for (Notification notification : notificationList) {
notification.checkNotification();
}
notificationRepository.saveAll(notificationList);

// 복사한 알림 목록을 사용하여 응답을 생성
return NotificationResponse.NotificationContentResponse.ListOf(notificationsToReturn);
return response;
}


Expand Down

0 comments on commit 489d59c

Please sign in to comment.