feat: support paginated notifications

This commit is contained in:
Tim
2025-08-19 18:45:56 +08:00
parent 1a12bec7b1
commit a64fd71bbe
7 changed files with 255 additions and 186 deletions

View File

@@ -45,7 +45,7 @@ class NotificationControllerTest {
p.setId(2L);
n.setPost(p);
n.setCreatedAt(LocalDateTime.now());
when(notificationService.listNotifications("alice", null))
when(notificationService.listNotifications("alice", 0, 30))
.thenReturn(List.of(n));
NotificationDto dto = new NotificationDto();
@@ -62,6 +62,23 @@ class NotificationControllerTest {
.andExpect(jsonPath("$[0].post.id").value(2));
}
@Test
void listUnreadNotifications() throws Exception {
Notification n = new Notification();
n.setId(1L);
when(notificationService.listUnreadNotifications("alice", 0, 30))
.thenReturn(List.of(n));
NotificationDto dto = new NotificationDto();
dto.setId(1L);
when(notificationMapper.toDto(n)).thenReturn(dto);
mockMvc.perform(get("/api/notifications/unread")
.principal(new UsernamePasswordAuthenticationToken("alice","p")))
.andExpect(status().isOk())
.andExpect(jsonPath("$[0].id").value(1));
}
@Test
void markReadEndpoint() throws Exception {
mockMvc.perform(post("/api/notifications/read")