Revert "feat: add paginated notification API and frontend support"

This reverts commit df7ca77652.
This commit is contained in:
tim
2025-08-19 17:23:36 +08:00
parent fbe2c66955
commit df49b21620
7 changed files with 184 additions and 255 deletions

View File

@@ -23,17 +23,9 @@ public class NotificationController {
private final NotificationMapper notificationMapper;
@GetMapping
public List<NotificationDto> list(@RequestParam(value = "page", defaultValue = "0") int page,
public List<NotificationDto> list(@RequestParam(value = "read", required = false) Boolean read,
Authentication auth) {
return notificationService.listNotifications(auth.getName(), null, page).stream()
.map(notificationMapper::toDto)
.collect(Collectors.toList());
}
@GetMapping("/unread")
public List<NotificationDto> listUnread(@RequestParam(value = "page", defaultValue = "0") int page,
Authentication auth) {
return notificationService.listNotifications(auth.getName(), false, page).stream()
return notificationService.listNotifications(auth.getName(), read).stream()
.map(notificationMapper::toDto)
.collect(Collectors.toList());
}

View File

@@ -5,8 +5,6 @@ import com.openisle.model.User;
import com.openisle.model.Post;
import com.openisle.model.Comment;
import com.openisle.model.NotificationType;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import java.util.List;
@@ -15,9 +13,6 @@ import java.util.List;
public interface NotificationRepository extends JpaRepository<Notification, Long> {
List<Notification> findByUserOrderByCreatedAtDesc(User user);
List<Notification> findByUserAndReadOrderByCreatedAtDesc(User user, boolean read);
Page<Notification> findByUserOrderByCreatedAtDesc(User user, Pageable pageable);
Page<Notification> findByUserAndReadOrderByCreatedAtDesc(User user, boolean read, Pageable pageable);
long countByUserAndRead(User user, boolean read);
List<Notification> findByPost(Post post);
List<Notification> findByComment(Comment comment);

View File

@@ -24,8 +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.Pageable;
/** Service for creating and retrieving notifications. */
@Service
@@ -183,21 +181,16 @@ public class NotificationService {
}
public List<Notification> listNotifications(String username, Boolean read) {
return listNotifications(username, read, 0);
}
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();
Page<Notification> p;
Pageable pageable = org.springframework.data.domain.PageRequest.of(page, 50);
List<Notification> list;
if (read == null) {
p = notificationRepository.findByUserOrderByCreatedAtDesc(user, pageable);
list = notificationRepository.findByUserOrderByCreatedAtDesc(user);
} else {
p = notificationRepository.findByUserAndReadOrderByCreatedAtDesc(user, read, pageable);
list = notificationRepository.findByUserAndReadOrderByCreatedAtDesc(user, read);
}
return p.getContent().stream().filter(n -> !disabled.contains(n.getType())).collect(Collectors.toList());
return list.stream().filter(n -> !disabled.contains(n.getType())).collect(Collectors.toList());
}
public void markRead(String username, List<Long> ids) {