blob: 92d6402f411a50dec2be79fdaac8b9d90e789d66 [file] [log] [blame]
// src/api/helpPost.js
import { api } from './auth'; // 复用已有的axios实例
export const createPost = (title, content, authorId, selectedImage) => {
// 创建 FormData 对象
const formData = new FormData();
formData.append('title', title);
formData.append('content', content);
formData.append('authorId', authorId);
// 如果有图片,添加到 FormData
if (selectedImage) {
formData.append('image', selectedImage);
}
return api.post('/help/posts', formData);
};
export const getPosts = (page = 1, size = 5) => {
return api.get('/help/posts', {
params: { page, size }
});
};
export const getPostDetail = (postId) => {
return api.get(`/help/posts/${postId}`);
};
export const likePost = (postId, data) => {
return api.post(`/help/posts/${postId}/like`, null, {
params: data
});
};
export const addPostComment = (postId, commentData) => {
// 创建FormData对象来处理文件上传
const formData = new FormData();
formData.append('authorId', commentData.authorId);
formData.append('content', commentData.content);
// 如果有图片,添加到formData
if (commentData.commentImage) {
formData.append('image', commentData.commentImage);
}
return api.post(`/help/posts/${postId}/comments`, formData);
};
export const deletePost = (postId, authorId) => {
return api.delete(`/help/posts/${postId}`, {
params: { authorId }
});
};
export const searchPosts = (keyword, page = 1, size = 5) => {
return api.get('/help/posts/search', {
params: { keyword, page, size }
});
};