-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
❇️ feat: NotificationQueryService 생성
NotificationQueryService 생성
- Loading branch information
1 parent
ef66e7c
commit 6c29f76
Showing
1 changed file
with
57 additions
and
0 deletions.
There are no files selected for viewing
57 changes: 57 additions & 0 deletions
57
src/main/java/foregg/foreggserver/service/notificationService/NotificationQueryService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
package foregg.foreggserver.service.notificationService; | ||
|
||
import foregg.foreggserver.converter.NotificationConverter; | ||
import foregg.foreggserver.domain.Notification; | ||
import foregg.foreggserver.domain.Reply; | ||
import foregg.foreggserver.domain.User; | ||
import foregg.foreggserver.dto.notificationDTO.NotificationResponseDTO; | ||
import foregg.foreggserver.jwt.SecurityUtil; | ||
import foregg.foreggserver.repository.NotificationRepository; | ||
import foregg.foreggserver.repository.ReplyRepository; | ||
import foregg.foreggserver.service.userService.UserQueryService; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
import java.time.LocalDateTime; | ||
import java.util.ArrayList; | ||
import java.util.Comparator; | ||
import java.util.List; | ||
|
||
@Service | ||
@Transactional(readOnly = true) | ||
@RequiredArgsConstructor | ||
public class NotificationQueryService { | ||
|
||
private final ReplyRepository replyRepository; | ||
private final UserQueryService userQueryService; | ||
private final NotificationRepository notificationRepository; | ||
|
||
public List<NotificationResponseDTO> getNotificationHistory() { | ||
|
||
List<NotificationResponseDTO> result = new ArrayList<>(); | ||
|
||
LocalDateTime thresholdDate = LocalDateTime.now().minusDays(30); | ||
User user = userQueryService.getUser(SecurityUtil.getCurrentUser()); | ||
|
||
// 필터링된 Reply 리스트 | ||
List<Reply> replyList = replyRepository.findByReceiver(user).stream() | ||
.filter(reply -> reply.getCreatedAt().isAfter(thresholdDate)) | ||
.toList(); | ||
|
||
// 필터링된 Notification 리스트 | ||
List<Notification> notificationList = notificationRepository.findByReceiver(user).stream() | ||
.filter(notification -> notification.getCreatedAt().isAfter(thresholdDate)) | ||
.toList(); | ||
|
||
// 결과 생성 | ||
result.addAll(NotificationConverter.fromReplyToNotification(replyList)); | ||
result.addAll(NotificationConverter.toNotificationResponse(notificationList)); | ||
|
||
// createdAt 순서로 정렬 | ||
result.sort(Comparator.comparing(NotificationResponseDTO::getCreatedAt).reversed()); | ||
|
||
return result; | ||
} | ||
|
||
} |