2026-01-28 08:07:06 +08:00
|
|
|
import api from './api';
|
|
|
|
|
|
|
|
|
|
export interface Notification {
|
|
|
|
|
id: number;
|
|
|
|
|
user_id: number;
|
|
|
|
|
title: string;
|
|
|
|
|
content: string;
|
|
|
|
|
type: string;
|
|
|
|
|
is_read: boolean;
|
|
|
|
|
link?: string;
|
|
|
|
|
read_at?: string;
|
|
|
|
|
created_at: string;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export interface NotificationListResponse {
|
|
|
|
|
success: boolean;
|
|
|
|
|
data: {
|
|
|
|
|
notifications: Notification[];
|
|
|
|
|
total: number;
|
|
|
|
|
page: number;
|
|
|
|
|
limit: number;
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export interface UnreadCountResponse {
|
|
|
|
|
success: boolean;
|
|
|
|
|
data: {
|
|
|
|
|
count: number;
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export const notificationService = {
|
|
|
|
|
getNotifications: (page: number = 1, limit: number = 10, isRead?: boolean) => {
|
2026-01-28 08:41:27 +08:00
|
|
|
const offset = (page - 1) * limit;
|
|
|
|
|
const params: Record<string, string | number | boolean> = { offset, limit };
|
2026-01-28 08:07:06 +08:00
|
|
|
if (isRead !== undefined) {
|
|
|
|
|
params.is_read = isRead;
|
|
|
|
|
}
|
|
|
|
|
return api.get<NotificationListResponse>('/notifications', params);
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
getUnreadCount: () => {
|
|
|
|
|
return api.get<UnreadCountResponse>('/notifications/unread-count');
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
markAsRead: (id: number) => {
|
|
|
|
|
return api.put<{ success: boolean }>(`/notifications/${id}/read`);
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
markAllAsRead: () => {
|
2026-01-28 08:41:27 +08:00
|
|
|
return api.post<{ success: boolean }>('/notifications/read-all');
|
2026-01-28 08:07:06 +08:00
|
|
|
}
|
|
|
|
|
};
|