feat: add paginated notification APIs and frontend

This commit is contained in:
Tim
2025-08-19 18:24:27 +08:00
parent 77856ff9af
commit 7dd1f1b3d0
5 changed files with 312 additions and 208 deletions

View File

@@ -180,15 +180,16 @@ public class NotificationService {
userRepository.save(user);
}
public List<Notification> listNotifications(String username, Boolean read) {
public List<Notification> listNotifications(String username, Boolean read, int page) {
User user = userRepository.findByUsername(username)
.orElseThrow(() -> new com.openisle.exception.NotFoundException("User not found"));
Set<NotificationType> disabled = user.getDisabledNotificationTypes();
List<Notification> list;
var pageable = org.springframework.data.domain.PageRequest.of(page, 50);
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());
}