DREW | 5b1883e | 2025-06-07 10:41:32 +0800 | [diff] [blame] | 1 | // src/api/notification.js |
| 2 | import axios from 'axios'; |
| 3 | import { api } from './auth'; |
| 4 | |
| 5 | |
| 6 | |
| 7 | export 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 | }; |