feat(web): fetch-based api client with 401 handling and tests

This commit is contained in:
2026-04-29 07:49:33 +08:00
parent 7c164f6aea
commit 3eb595cf5e
6 changed files with 181 additions and 0 deletions
+15
View File
@@ -0,0 +1,15 @@
import { request } from './client'
import type { Notification } from '@/stores/notifications'
export const notificationsApi = {
list: (unreadOnly = false, limit = 50) =>
request<{ items: Notification[] }>(
`/api/v1/notifications?unread=${unreadOnly}&limit=${limit}`,
),
unreadCount: () =>
request<{ count: number }>('/api/v1/notifications/unread-count'),
markRead: (id: string) =>
request<void>(`/api/v1/notifications/${id}/read`, { method: 'PATCH' }),
markAllRead: () =>
request<void>('/api/v1/notifications/read-all', { method: 'PATCH' }),
}