From 29fa6455fc8ef5d70cdf25257d54ed863388076e Mon Sep 17 00:00:00 2001 From: bo-ram-bo-ram Date: Tue, 23 Apr 2024 01:57:24 +0900 Subject: [PATCH] =?UTF-8?q?[feat]=20service=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/NotificationQueryService.java | 27 +++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/DontBeServer/src/main/java/com/dontbe/www/DontBeServer/api/notification/service/NotificationQueryService.java b/DontBeServer/src/main/java/com/dontbe/www/DontBeServer/api/notification/service/NotificationQueryService.java index b87f8d1..3028702 100644 --- a/DontBeServer/src/main/java/com/dontbe/www/DontBeServer/api/notification/service/NotificationQueryService.java +++ b/DontBeServer/src/main/java/com/dontbe/www/DontBeServer/api/notification/service/NotificationQueryService.java @@ -8,6 +8,7 @@ import com.dontbe.www.DontBeServer.api.notification.dto.response.NotificaitonCountResponseDto; import com.dontbe.www.DontBeServer.api.notification.dto.response.NotificationAllResponseDto; import com.dontbe.www.DontBeServer.api.notification.dto.response.NotificationAllResponseDtoVer2; +import com.dontbe.www.DontBeServer.api.notification.dto.response.NotificationAllResponseDtoVer3; import com.dontbe.www.DontBeServer.api.notification.repository.NotificationRepository; import lombok.RequiredArgsConstructor; import org.springframework.beans.factory.annotation.Value; @@ -77,6 +78,32 @@ public List getNotificationAllPagination(Long me )).collect(Collectors.toList()); } + public List getNotifications(Long memberId, Long cursor){ + Member usingMember = memberRepository.findMemberByIdOrThrow(memberId); + + PageRequest pageRequest = PageRequest.of(0, NOTIFICATION_DEFAULT_PAGE_SIZE); + Slice notificationList; + + if(cursor==-1){ + notificationList = notificationRepository.findTop15ByNotificationTargetMemberOrderByCreatedAtDesc(usingMember, pageRequest); + }else{ + notificationList = notificationRepository.findNotificationsNextPage(cursor, memberId, pageRequest); + } + + return notificationList.stream() + .map(oneNotification -> NotificationAllResponseDtoVer3.of( + usingMember, + isSystemOrUser(oneNotification.getNotificationTriggerMemberId()), + oneNotification, + oneNotification.isNotificationChecked(), + refineNotificationTriggerId(oneNotification.getNotificationTriggerType(), + oneNotification.getNotificationTriggerId(), oneNotification), + profileUrl(oneNotification.getId(), oneNotification.getNotificationTriggerType()), + isDeletedMember(oneNotification.getNotificationTriggerMemberId()), + oneNotification.getNotificationTriggerMemberId() + )).collect(Collectors.toList()); + } + private long refineNotificationTriggerId (String triggerType, Long triggerId, Notification notification){ // Comment comment = commentRepository.findCommentByIdOrThrow(triggerId);