Revert "feat: support paginated notifications"

This reverts commit a64fd71bbe.
This commit is contained in:
tim
2025-08-19 19:01:54 +08:00
parent 3258a42b44
commit 3f2829cd37
7 changed files with 185 additions and 254 deletions

View File

@@ -24,10 +24,6 @@ import java.util.List;
import java.util.ArrayList;
import java.util.concurrent.Executor;
import java.util.stream.Collectors;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
/** Service for creating and retrieving notifications. */
@Service
@@ -184,24 +180,15 @@ public class NotificationService {
userRepository.save(user);
}
public List<Notification> listNotifications(String username, int page, int size) {
return listNotifications(username, null, page, size);
}
public List<Notification> listUnreadNotifications(String username, int page, int size) {
return listNotifications(username, false, page, size);
}
private List<Notification> listNotifications(String username, Boolean read, int page, int size) {
public List<Notification> listNotifications(String username, Boolean read) {
User user = userRepository.findByUsername(username)
.orElseThrow(() -> new com.openisle.exception.NotFoundException("User not found"));
Set<NotificationType> disabled = user.getDisabledNotificationTypes();
Pageable pageable = PageRequest.of(page, size, Sort.by(Sort.Direction.DESC, "createdAt"));
Page<Notification> list;
List<Notification> list;
if (read == null) {
list = notificationRepository.findByUser(user, pageable);
list = notificationRepository.findByUserOrderByCreatedAtDesc(user);
} else {
list = notificationRepository.findByUserAndRead(user, read, pageable);
list = notificationRepository.findByUserAndReadOrderByCreatedAtDesc(user, read);
}
return list.stream().filter(n -> !disabled.contains(n.getType())).collect(Collectors.toList());
}