支持评论点赞与举报,并统一帖子/评论的举报入口交互。

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
2026-08-06 01:06:02 +08:00
parent c05cc472cf
commit b075495540
13 changed files with 595 additions and 90 deletions

View File

@@ -370,6 +370,16 @@ func (h *Handlers) APIToggleLike(c *gin.Context) {
c.JSON(http.StatusOK, gin.H{"liked": liked, "like_count": post.LikeCount})
}
func (h *Handlers) APIToggleCommentLike(c *gin.Context) {
id, _ := strconv.ParseUint(c.Param("id"), 10, 64)
liked, likeCount, err := h.Comment.ToggleLike(h.currentUserID(c), uint(id))
if err != nil {
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
return
}
c.JSON(http.StatusOK, gin.H{"liked": liked, "like_count": likeCount})
}
func (h *Handlers) APIToggleFavorite(c *gin.Context) {
id, _ := strconv.ParseUint(c.Param("id"), 10, 64)
faved, err := h.Post.ToggleFavorite(h.currentUserID(c), uint(id))

View File

@@ -29,6 +29,25 @@ func (h *Handlers) APICreatePostReport(c *gin.Context) {
c.JSON(http.StatusOK, gin.H{"message": "举报已提交,感谢反馈", "report": rep})
}
// APICreateCommentReport 举报评论
func (h *Handlers) APICreateCommentReport(c *gin.Context) {
commentID, _ := strconv.ParseUint(c.Param("id"), 10, 64)
var req struct {
Reason string `json:"reason"`
Detail string `json:"detail"`
}
if err := c.ShouldBindJSON(&req); err != nil {
c.JSON(http.StatusBadRequest, gin.H{"error": "参数错误"})
return
}
rep, err := h.Report.CreateCommentReport(h.currentUserID(c), uint(commentID), req.Reason, req.Detail)
if err != nil {
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
return
}
c.JSON(http.StatusOK, gin.H{"message": "举报已提交,感谢反馈", "report": rep})
}
// APIAdminReports 举报列表
func (h *Handlers) APIAdminReports(c *gin.Context) {
page, _ := strconv.Atoi(c.DefaultQuery("page", "1"))