blob: 84264b8620b32ed84bdea8f230c9fd191b0a4d12 [file] [log] [blame]
DREW5b1883e2025-06-07 10:41:32 +08001// src/api/notification.js
2import axios from 'axios';
3import { api } from './auth';
4
5
6
7export const notificationApi = {
8 // 获取用户通知列表
9 async getNotifications(userId) {
10 try {
11 const response = await api.get(`/api/notifications`, {
12 params: { userId }
13 });
14 return response.data;
15 } catch (error) {
16 console.error('获取通知列表失败:', error);
17 throw error;
18 }
19 },
20
21 // 标记通知为已读 - 更新为处理返回的notification对象
22 async markNotificationAsRead(notificationId) {
23 try {
24 const response = await api.post(`/api/notifications/${notificationId}/read`);
25 return {
26 success: true,
27 notification: response.data.notification // 获取后端返回的更新后通知
28 };
29 } catch (error) {
30 console.error('标记通知为已读失败:', error);
31 return {
32 success: false,
33 message: error.response?.data?.message || '标记已读失败'
34 };
35 }
36 }
37};