70 lines
1.9 KiB
TypeScript
70 lines
1.9 KiB
TypeScript
/**
|
|
* @description 用户收藏相关API
|
|
* @author yslg
|
|
* @since 2025-10-15
|
|
*/
|
|
|
|
import { api } from '@/apis/index';
|
|
import type { UserCollection, ResultDomain } from '@/types';
|
|
|
|
/**
|
|
* 用户收藏API服务
|
|
*/
|
|
export const userCollectionApi = {
|
|
baseUrl: '/usercenter/collections',
|
|
/**
|
|
* 获取用户收藏列表
|
|
* @param userID 用户ID
|
|
* @param collectionType 收藏类型
|
|
* @returns Promise<ResultDomain<UserCollection>>
|
|
*/
|
|
async getUserCollections(userID: string, collectionType?: number): Promise<ResultDomain<UserCollection>> {
|
|
const response = await api.get<UserCollection>(`${this.baseUrl}/list`, {
|
|
userID,
|
|
collectionType
|
|
});
|
|
return response.data;
|
|
},
|
|
|
|
/**
|
|
* 添加收藏
|
|
* @param collection 收藏数据
|
|
* @returns Promise<ResultDomain<UserCollection>>
|
|
*/
|
|
async addCollection(collection: UserCollection): Promise<ResultDomain<UserCollection>> {
|
|
const response = await api.post<UserCollection>(`${this.baseUrl}/collect`, collection);
|
|
return response.data;
|
|
},
|
|
|
|
/**
|
|
* 取消收藏
|
|
* @param userID 用户ID
|
|
* @param collectionType 收藏类型
|
|
* @param collectionID 收藏对象ID
|
|
* @returns Promise<ResultDomain<boolean>>
|
|
*/
|
|
async removeCollection(userID: string, collectionType: number, collectionID: string): Promise<ResultDomain<boolean>> {
|
|
const response = await api.delete<boolean>(`${this.baseUrl}/collect`, {
|
|
userID,
|
|
collectionType,
|
|
collectionID
|
|
});
|
|
return response.data;
|
|
},
|
|
|
|
/**
|
|
* 检查是否已收藏
|
|
* @param userID 用户ID
|
|
* @param collectionType 收藏类型
|
|
* @param collectionID 收藏对象ID
|
|
* @returns Promise<ResultDomain<boolean>>
|
|
*/
|
|
async isCollected(collectionType: number, collectionID: string): Promise<ResultDomain<boolean>> {
|
|
const response = await api.get<boolean>(`${this.baseUrl}/check`, {
|
|
collectionType,
|
|
collectionID
|
|
});
|
|
return response.data;
|
|
}
|
|
};
|