Skip to content

Commit

Permalink
[feat] service 구현
Browse files Browse the repository at this point in the history
  • Loading branch information
bo-ram-bo-ram committed Apr 22, 2024
1 parent 57f5216 commit 29fa645
Showing 1 changed file with 27 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -77,6 +78,32 @@ public List<NotificationAllResponseDtoVer2> getNotificationAllPagination(Long me
)).collect(Collectors.toList());
}

public List<NotificationAllResponseDtoVer3> getNotifications(Long memberId, Long cursor){
Member usingMember = memberRepository.findMemberByIdOrThrow(memberId);

PageRequest pageRequest = PageRequest.of(0, NOTIFICATION_DEFAULT_PAGE_SIZE);
Slice<Notification> 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);
Expand Down

0 comments on commit 29fa645

Please sign in to comment.