ym923 | 6e0ddcf | 2025-06-09 20:14:11 +0800 | [diff] [blame] | 1 | import axios from 'axios'; |
| 2 | |
| 3 | const BASE_URL = 'http://localhost:8080/friends'; |
| 4 | |
| 5 | // 添加好友(发起好友请求) |
| 6 | export const addFriend = (friendData) => { |
| 7 | return axios.post(`${BASE_URL}/add`, friendData); |
| 8 | }; |
| 9 | |
| 10 | // 同意好友申请 |
| 11 | export const acceptFriend = (friend1, friend2) => { |
| 12 | return axios.post(`${BASE_URL}/accept`, null, { |
| 13 | params: { friend1, friend2 } |
| 14 | }); |
| 15 | }; |
| 16 | |
| 17 | // 拒绝好友申请(删除 pending 状态的好友关系) |
| 18 | export const rejectFriend = (friend1, friend2) => { |
| 19 | return axios.delete(`${BASE_URL}/delete`, { |
| 20 | params: { friend1, friend2 } |
| 21 | }); |
| 22 | }; |
| 23 | |
| 24 | // 删除好友 |
| 25 | export const deleteFriend = (friend1, friend2) => { |
| 26 | return axios.delete(`${BASE_URL}/delete`, { |
| 27 | params: { friend1, friend2 } |
| 28 | }); |
| 29 | }; |
| 30 | |
| 31 | // 查询某用户所有已通过好友 |
| 32 | export const getFriendsByUserId = (userid) => { |
| 33 | return axios.get(`${BASE_URL}/list/${userid}`); |
| 34 | }; |
| 35 | |
| 36 | // 查询某用户收到的好友申请(pending 状态) |
| 37 | export const getPendingRequests = (userid) => { |
| 38 | return axios.get(`${BASE_URL}/pending/${userid}`); |
| 39 | }; |