import FetchRequest from "@/api/FetchRequest"; import type Friend from "@/mode/Friend"; class FriendApi { static url = "/api/sys/friends"; /** * 获取用户的所有好友 * @param id 用户ID */ static friends(): Promise { return FetchRequest.get(`${this.url}?state=0`, true); } /** * 获取用户的待审核好友 */ static validateList(): Promise { return FetchRequest.get(`${this.url}/validateList`, true); } /** * 添加好友 * @param friend 好友 */ static add(friend: Friend): Promise { return FetchRequest.post(`${this.url}/add`, JSON.stringify(friend), true); } /** * 审核好友 * @param userId 用户ID * @param friendId 好友 * @param state 状态 */ static check(userId: string, friendId: string, state: string): Promise { const data = { friendId: friendId.toString(), state: state.toString(), }; console.log('check',data) return FetchRequest.patch( `${this.url}/${userId}`, JSON.stringify(data), true ); } /** * 同意加好友 * @param friendId 好友ID */ static agree(friendId: string): Promise { return FetchRequest.post(`${this.url}/agree`, friendId, true); } /** * 删除好友 * @param friendId 好友ID */ static delete(friendId: string): Promise { return FetchRequest.del(`${this.url}/delete`, friendId, true); } /** * 判断是否好友 */ static isFriend(friendId: string): Promise { return FetchRequest.get(`${this.url}/isFriend?friendId=${friendId}`, true); } } export default FriendApi;