- 新增热门帖子、热门作者、榜单接口及实现 - 新增api-documentation,更好的ai协作 - 修复types没有导出的问题 BREAKING CHANGES: 1.0.0->1.1.0(latest)
80 lines
2.3 KiB
TypeScript
80 lines
2.3 KiB
TypeScript
import type { AxiosRequestConfig } from 'axios';
|
|
import type { ApiClient } from '../types';
|
|
import type {
|
|
CreatePostRequest,
|
|
CreatePostResponse,
|
|
GetPostsRequest,
|
|
GetPostsResponse,
|
|
GetPostRequest,
|
|
GetPostResponse,
|
|
LikePostRequest,
|
|
LikePostResponse,
|
|
BookmarkPostRequest,
|
|
BookmarkPostResponse,
|
|
CreateCommentRequest,
|
|
CreateCommentResponse,
|
|
GetCommentsRequest,
|
|
GetCommentsResponse,
|
|
LikeCommentRequest,
|
|
LikeCommentResponse,
|
|
GetHotPostsRequest,
|
|
GetHotPostsResponse,
|
|
GetPostRankingRequest,
|
|
GetPostRankingResponse
|
|
} from '@/types/post/api';
|
|
|
|
// 帖子API服务工厂函数
|
|
export const postApi = (client: ApiClient) => ({
|
|
// 创建帖子
|
|
createPost: (data: CreatePostRequest): Promise<CreatePostResponse> => {
|
|
return client.post('/posts', data);
|
|
},
|
|
|
|
// 获取帖子列表
|
|
getPosts: (params: GetPostsRequest): Promise<GetPostsResponse> => {
|
|
const config: AxiosRequestConfig = { params };
|
|
return client.get('/posts', config);
|
|
},
|
|
|
|
// 获取帖子详情
|
|
getPost: ({ postId }: GetPostRequest): Promise<GetPostResponse> => {
|
|
return client.get(`/posts/${postId}`);
|
|
},
|
|
|
|
// 点赞帖子
|
|
likePost: ({ postId }: LikePostRequest): Promise<LikePostResponse> => {
|
|
return client.put(`/posts/${postId}/like`);
|
|
},
|
|
|
|
// 收藏帖子
|
|
bookmarkPost: ({ postId }: BookmarkPostRequest): Promise<BookmarkPostResponse> => {
|
|
return client.put(`/posts/${postId}/bookmark`);
|
|
},
|
|
|
|
// 创建评论
|
|
createComment: (data: CreateCommentRequest): Promise<CreateCommentResponse> => {
|
|
return client.post(`/posts/${data.postId}/comments`, data);
|
|
},
|
|
|
|
// 获取评论列表
|
|
getComments: (params: GetCommentsRequest): Promise<GetCommentsResponse> => {
|
|
const { postId, ...queryParams } = params;
|
|
return client.get(`/posts/${postId}/comments`, { params: queryParams });
|
|
},
|
|
|
|
// 点赞评论
|
|
likeComment: ({ commentId }: LikeCommentRequest): Promise<LikeCommentResponse> => {
|
|
return client.put(`/comments/${commentId}/like`);
|
|
},
|
|
|
|
// 获取热门帖子
|
|
getHotPosts: (params: GetHotPostsRequest = {}): Promise<GetHotPostsResponse> => {
|
|
return client.get('/posts/hot', { params });
|
|
},
|
|
|
|
// 获取帖子榜单
|
|
getPostRanking: (params: GetPostRankingRequest = {}): Promise<GetPostRankingResponse> => {
|
|
return client.get('/posts/ranking', { params });
|
|
}
|
|
});
|