feat: add paginated notification APIs and frontend support

This commit is contained in:
Tim
2025-08-19 19:34:13 +08:00
parent 3f2829cd37
commit c344b5b4ae
5 changed files with 341 additions and 205 deletions

View File

@@ -180,15 +180,21 @@ public class NotificationService {
userRepository.save(user);
}
public List<Notification> listNotifications(String username, Boolean read) {
public List<Notification> listNotifications(String username, Boolean read, int page, int size) {
User user = userRepository.findByUsername(username)
.orElseThrow(() -> new com.openisle.exception.NotFoundException("User not found"));
Set<NotificationType> disabled = user.getDisabledNotificationTypes();
org.springframework.data.domain.Pageable pageable =
org.springframework.data.domain.PageRequest.of(page, size);
List<Notification> list;
if (read == null) {
list = notificationRepository.findByUserOrderByCreatedAtDesc(user);
list = notificationRepository
.findByUserOrderByCreatedAtDesc(user, pageable)
.getContent();
} else {
list = notificationRepository.findByUserAndReadOrderByCreatedAtDesc(user, read);
list = notificationRepository
.findByUserAndReadOrderByCreatedAtDesc(user, read, pageable)
.getContent();
}
return list.stream().filter(n -> !disabled.contains(n.getType())).collect(Collectors.toList());
}