web-文件接口
This commit is contained in:
69
schoolNewsWeb/src/apis/usercenter/collection.ts
Normal file
69
schoolNewsWeb/src/apis/usercenter/collection.ts
Normal file
@@ -0,0 +1,69 @@
|
||||
/**
|
||||
* @description 用户收藏相关API
|
||||
* @author yslg
|
||||
* @since 2025-10-15
|
||||
*/
|
||||
|
||||
import { api } from '@/apis/index';
|
||||
import type { UserCollection, ResultDomain } from '@/types';
|
||||
|
||||
/**
|
||||
* 用户收藏API服务
|
||||
*/
|
||||
export const userCollectionApi = {
|
||||
/**
|
||||
* 获取用户收藏列表
|
||||
* @param userID 用户ID
|
||||
* @param collectionType 收藏类型
|
||||
* @returns Promise<ResultDomain<UserCollection>>
|
||||
*/
|
||||
async getUserCollections(userID: string, collectionType?: number): Promise<ResultDomain<UserCollection>> {
|
||||
const response = await api.get<UserCollection>('/usercenter/collection/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>('/usercenter/collection/add', 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>('/usercenter/collection/remove', {
|
||||
userID,
|
||||
collectionType,
|
||||
collectionID
|
||||
});
|
||||
return response.data;
|
||||
},
|
||||
|
||||
/**
|
||||
* 检查是否已收藏
|
||||
* @param userID 用户ID
|
||||
* @param collectionType 收藏类型
|
||||
* @param collectionID 收藏对象ID
|
||||
* @returns Promise<ResultDomain<boolean>>
|
||||
*/
|
||||
async isCollected(userID: string, collectionType: number, collectionID: string): Promise<ResultDomain<boolean>> {
|
||||
const response = await api.get<boolean>('/usercenter/collection/check', {
|
||||
userID,
|
||||
collectionType,
|
||||
collectionID
|
||||
});
|
||||
return response.data;
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user