blob: 28b2b4e58deaa1562e4bb7e7b56c35efddaaf61d [file] [log] [blame]
ym923ed3de702025-06-09 20:10:16 +08001import axios from 'axios';
2
3const BASE_URL = 'http://localhost:8080/comment';
4
5// 创建评论
6export const createComment = (commentData) => {
7 return axios.post(`${BASE_URL}/create`, commentData);
8};
9
10// 删除评论
11export const deleteComment = (commentId) => {
12 return axios.delete(`${BASE_URL}/delete/${commentId}`);
13};
14
15// 更新评论
16export const updateComment = (commentData) => {
17 return axios.put(`${BASE_URL}/update`, commentData);
18};
19
20// 获取某个帖子的所有评论
21// comment.js
22export async function getCommentsByPostId(postid) {
23 try {
24 const response = await axios.get(`${BASE_URL}/post/${postid}`);
25 return Array.isArray(response.data) ? response.data : []; // 确保返回数据是数组
26 } catch (error) {
27 console.error('获取评论失败', error);
28 return [];
29 }
30}
31
32// 点赞评论
33export const likeComment = (commentId) => {
34 return axios.post(`${BASE_URL}/like/${commentId}`);
35};
36
37// 取消点赞评论
38export const unlikeComment = (commentId) => {
39 return axios.post(`${BASE_URL}/unlike/${commentId}`);
40};