- Service 层:energy_service → energize/operations/admin/query 四文件 - Service 层:post_service → helpers/audit + 核心 CRUD 保留 - Service 层:favorite_service → items + 核心文件夹操作保留 - Service 层:auth_service → password + 核心注册/登录保留 - Service 层:notification_service → notify + 核心列表/已读保留 - Service 层:audit_service → review + 核心列表/详情保留 - Controller 层:studio_controller → page/write/api/post_api/action 五文件 - Controller 层:post_controller → page/api/upload 三文件 - Controller 层:comment_controller → list/write/action/upload 四文件 - 清理未使用导入(notification_service.go 移除 fmt)
53 lines
1.4 KiB
Go
53 lines
1.4 KiB
Go
package controller
|
|
|
|
import (
|
|
"net/http"
|
|
"strconv"
|
|
|
|
"metazone.cc/metalab/internal/common"
|
|
|
|
"github.com/gin-gonic/gin"
|
|
)
|
|
|
|
// ListRootComments 获取文章顶级评论 GET /api/posts/:id/comments
|
|
func (ctrl *CommentController) ListRootComments(c *gin.Context) {
|
|
postID, err := strconv.ParseUint(c.Param("id"), 10, 64)
|
|
if err != nil {
|
|
common.Error(c, http.StatusBadRequest, "无效的文章ID")
|
|
return
|
|
}
|
|
|
|
page, _ := strconv.Atoi(c.DefaultQuery("page", "1"))
|
|
pageSize, _ := strconv.Atoi(c.DefaultQuery("page_size", "20"))
|
|
|
|
comments, total, err := ctrl.commentService.ListRootComments(uint(postID), page, pageSize)
|
|
if err != nil {
|
|
common.Error(c, http.StatusInternalServerError, "获取评论失败")
|
|
return
|
|
}
|
|
|
|
common.Ok(c, gin.H{
|
|
"items": comments,
|
|
"total": total,
|
|
"page": page,
|
|
"total_pages": common.PageCount(total, pageSize),
|
|
})
|
|
}
|
|
|
|
// ListReplies 获取顶级评论的全部回复 GET /api/posts/:id/comments/:root_id/replies
|
|
func (ctrl *CommentController) ListReplies(c *gin.Context) {
|
|
rootID, err := strconv.ParseUint(c.Param("root_id"), 10, 64)
|
|
if err != nil {
|
|
common.Error(c, http.StatusBadRequest, "无效的评论ID")
|
|
return
|
|
}
|
|
|
|
replies, err := ctrl.commentService.ListReplies(uint(rootID))
|
|
if err != nil {
|
|
common.Error(c, http.StatusInternalServerError, "获取回复失败")
|
|
return
|
|
}
|
|
|
|
common.Ok(c, gin.H{"replies": replies})
|
|
}
|