修复查看帖子、评论、回复评论、点赞、收藏,添加用户等级

Change-Id: Ida9590d7ccee08dcd787a36c7e5cb39a3e26cd0d
diff --git a/src/pages/Forum/posts-detail/api.js b/src/pages/Forum/posts-detail/api.js
index 27c3a18..53dbfd3 100644
--- a/src/pages/Forum/posts-detail/api.js
+++ b/src/pages/Forum/posts-detail/api.js
@@ -1,46 +1,60 @@
 import axios from 'axios';
 
-const API_BASE = process.env.REACT_APP_API_BASE;
+
 
 
 // 获取帖子详情
 export const getPostDetail = async (post_id) => {
-    const response = await axios.get(`${API_BASE}/echo/forum/posts/${post_id}/getPost`);
+    const response = await axios.get(`/echo/forum/posts/${post_id}/getPost`);
     return response.data;
 };
 
 // 获取帖子评论
 export const getPostComments = async (post_id) => {
-    const response = await axios.get(`${API_BASE}/echo/forum/posts/${post_id}/getAllComments`);
+    const response = await axios.get(`/echo/forum/posts/${post_id}/getAllComments`);
+    return response.data;
+};
+
+// 添加评论
+export const addCommentToPost = async (postId, commentPayload) => {
+  const res = await fetch(`/echo/forum/posts/${postId}/comments`, {
+    method: 'POST',
+    headers: { 'Content-Type': 'application/json' },
+    body: JSON.stringify(commentPayload),
+  });
+
+  if (!res.ok) {
+    throw new Error('请求失败,状态码:' + res.status);
+  }
+
+  // 试着解析 JSON,如果失败则返回 null(可能是空响应)
+  try {
+    const data = await res.json();
+    return data;
+  } catch {
+    return null;
+  }
+};
+
+
+
+// 点赞评论
+export const likeComment = async (commentId) => {
+    const response = await axios.post(`/echo/forum/comments/${commentId}/like`);
+    return response.data;
+};
+
+// 取消点赞评论
+export const unlikeComment = async (commentId) => {
+    const response = await axios.delete(`/echo/forum/comments/${commentId}/unlike`);
     return response.data;
 };
 
 // 点赞帖子
 export const likePost = async (post_id, userId) => {
     try {
-        const response = await axios.post(`${API_BASE}/echo/forum/posts/${post_id}/like`, {
-            user_id: userId,  // 用户 ID
-        });
-        return response.data;
-    } catch (error) {
-        return handleApiError(error);
-    }
-};
-
-// 取消点赞帖子
-export const unlikePost = async (post_id) => {
-    const response = await axios.delete(`${API_BASE}/echo/forum/posts/${post_id}/unlike`);
-    return response.data;
-};
-
-// 添加评论
-export const addCommentToPost = async (post_id, userId, content, isAnonymous, comCommentId = null) => {
-    try {
-        const response = await axios.post(`${API_BASE}/echo/forum/posts/${post_id}/comments`, {
-            content,
+        const response = await axios.post(`/echo/forum/posts/${post_id}/like`, {
             user_id: userId,
-            is_anonymous: isAnonymous,
-            com_comment_id: comCommentId, // 如果是回复评论,传递 com_comment_id
         });
         return response.data;
     } catch (error) {
@@ -48,24 +62,23 @@
     }
 };
 
-// 点赞评论
-export const likeComment = async (commentId) => {
-    const response = await axios.post(`${API_BASE}/echo/forum/comments/${commentId}/like`);
-    return response.data;
-};
-
-// 取消点赞评论
-export const unlikeComment = async (commentId) => {
-    const response = await axios.delete(`${API_BASE}/echo/forum/comments/${commentId}/unlike`);
-    return response.data;
+// 取消点赞帖子(改为 POST 请求,携带 user_id)
+export const unlikePost = async (post_id, userId) => {
+    try {
+        const response = await axios.post(`/echo/forum/posts/${post_id}/unlike`, {
+            user_id: userId,
+        });
+        return response.data;
+    } catch (error) {
+        return handleApiError(error);
+    }
 };
 
 // 收藏帖子
-export const collectPost = async (post_id, userId, action) => {
+export const collectPost = async (post_id, userId) => {
     try {
-        const response = await axios.post(`${API_BASE}/echo/forum/posts/${post_id}/collect`, {
+        const response = await axios.post(`/echo/forum/posts/${post_id}/collect`, {
             user_id: userId,
-            action: action,  // "collect" 或 "cancel"
         });
         return response.data;
     } catch (error) {
@@ -73,17 +86,21 @@
     }
 };
 
-// // 取消收藏帖子
-// export const uncollectPost = async (post_id, userId) => {
-//     const response = await axios.post(`${API_BASE}/echo/forum/posts/${post_id}/uncollect`, {
-//         user_id: userId,  // 用户 ID
-//     });
-//     return response.data;
-// };
+// 取消收藏帖子(使用 POST 请求)
+export const uncollectPost = async (post_id, userId) => {
+    try {
+        const response = await axios.post(`/echo/forum/posts/${post_id}/uncollect`, {
+            user_id: userId,
+        });
+        return response.data;
+    } catch (error) {
+        return handleApiError(error);
+    }
+};
 
-// 获取用户信息
+
 export const getUserInfo = async (userId) => {
-    const response = await axios.get(`${API_BASE}/user/${userId}/info`);
+    const response = await axios.get(`/user/${userId}/info`);
     return response.data;
 };