feat(image): 新建 knowai-core:1.0.0 镜像并完成推送
Some checks reported errors
continuous-integration/drone/push Build was killed
Some checks reported errors
continuous-integration/drone/push Build was killed
- 搭建 api、auth、utils 等逻辑模块 - 通过 tsc、eslint、vitest 测试验证 BREAKING CHANGE: 新镜像分支
This commit is contained in:
65
api/modules/post.ts
Normal file
65
api/modules/post.ts
Normal file
@@ -0,0 +1,65 @@
|
||||
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
|
||||
} 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`);
|
||||
}
|
||||
});
|
||||
Reference in New Issue
Block a user