mirror of
https://github.com/nagisa77/OpenIsle.git
synced 2026-02-15 19:41:02 +08:00
Revert "feat: add paginated notification APIs and frontend support"
This reverts commit c344b5b4ae.
This commit is contained in:
@@ -24,19 +24,8 @@ public class NotificationController {
|
||||
|
||||
@GetMapping
|
||||
public List<NotificationDto> list(@RequestParam(value = "read", required = false) Boolean read,
|
||||
@RequestParam(value = "page", defaultValue = "0") int page,
|
||||
@RequestParam(value = "size", defaultValue = "30") int size,
|
||||
Authentication auth) {
|
||||
return notificationService.listNotifications(auth.getName(), read, page, size).stream()
|
||||
.map(notificationMapper::toDto)
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
@GetMapping("/unread")
|
||||
public List<NotificationDto> listUnread(@RequestParam(value = "page", defaultValue = "0") int page,
|
||||
@RequestParam(value = "size", defaultValue = "30") int size,
|
||||
Authentication auth) {
|
||||
return notificationService.listNotifications(auth.getName(), false, page, size).stream()
|
||||
return notificationService.listNotifications(auth.getName(), read).stream()
|
||||
.map(notificationMapper::toDto)
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
@@ -6,8 +6,6 @@ import com.openisle.model.Post;
|
||||
import com.openisle.model.Comment;
|
||||
import com.openisle.model.NotificationType;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@@ -15,8 +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);
|
||||
|
||||
@@ -180,21 +180,15 @@ public class NotificationService {
|
||||
userRepository.save(user);
|
||||
}
|
||||
|
||||
public 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();
|
||||
org.springframework.data.domain.Pageable pageable =
|
||||
org.springframework.data.domain.PageRequest.of(page, size);
|
||||
List<Notification> list;
|
||||
if (read == null) {
|
||||
list = notificationRepository
|
||||
.findByUserOrderByCreatedAtDesc(user, pageable)
|
||||
.getContent();
|
||||
list = notificationRepository.findByUserOrderByCreatedAtDesc(user);
|
||||
} else {
|
||||
list = notificationRepository
|
||||
.findByUserAndReadOrderByCreatedAtDesc(user, read, pageable)
|
||||
.getContent();
|
||||
list = notificationRepository.findByUserAndReadOrderByCreatedAtDesc(user, read);
|
||||
}
|
||||
return list.stream().filter(n -> !disabled.contains(n.getType())).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user