This commit is contained in:
谢宇宁
2026-09-29 15:30:33 +07:00
parent 0fbdba5ccf
commit 9abe0b1b76
181 changed files with 608 additions and 18501 deletions
-112
View File
@@ -3,7 +3,6 @@ package web
import (
"net/http"
"strconv"
"strings"
"videoweb/app/service/commentser"
"github.com/gin-gonic/gin"
@@ -42,114 +41,3 @@ func CommentList(c *gin.Context) {
}
// CommentSend BFF:代理 POST /api/app/comment/send。
// 文档:http://172.104.181.99:25319/swagger/index.html#/评论APP/post_api_app_comment_send
func CommentSend(c *gin.Context) {
var req commentser.CommentSendReq
if err := c.ShouldBindJSON(&req); err != nil {
c.JSON(http.StatusBadRequest, gin.H{
"code": 400,
"msg": "invalid body",
"tip": "参数错误",
"data": nil,
})
return
}
env, err := commentser.Send(c, req)
if err != nil {
tip := "发布失败"
msg := err.Error()
switch {
case strings.Contains(msg, "empty text"):
tip = "请输入评论内容"
case strings.Contains(msg, "too long"):
tip = "评论不能超过 200 字"
case strings.Contains(msg, "invalid objectId"):
tip = "缺少评论对象"
}
c.JSON(http.StatusOK, gin.H{
"code": 400,
"msg": msg,
"tip": tip,
"data": nil,
})
return
}
if env == nil {
c.JSON(http.StatusOK, gin.H{
"code": 500,
"msg": "empty response",
"tip": "发布失败",
"data": nil,
})
return
}
tip := env.Tip
if tip == "" {
tip = env.Msg
}
// 上游参数错误兜底提示(例如 objectType 不被支持)
if env.Code == 1001 && (tip == "" || tip == "参数错误") {
tip = "评论参数错误,请稍后重试"
}
c.JSON(http.StatusOK, gin.H{
"code": env.Code,
"msg": env.Msg,
"tip": tip,
"data": env.Data,
})
}
// CommentLikeSet BFF:代理 POST /api/app/comment/like/set。
// 文档:http://172.104.181.99:25319/swagger/index.html#/评论APP/post_api_app_comment_like_set
func CommentLikeSet(c *gin.Context) {
var body struct {
CommentID int64 `json:"commentId"`
IsLike *bool `json:"isLike"`
}
if err := c.ShouldBindJSON(&body); err != nil {
c.JSON(http.StatusBadRequest, gin.H{
"code": 400,
"msg": "invalid body",
"tip": "参数错误",
"data": nil,
})
return
}
if body.CommentID <= 0 || body.IsLike == nil {
c.JSON(http.StatusOK, gin.H{
"code": 400,
"msg": "commentId/isLike required",
"tip": "缺少评论 ID 或点赞状态",
"data": nil,
})
return
}
env, err := commentser.LikeSet(c, commentser.CommentLikeSetReq{
CommentID: body.CommentID,
IsLike: *body.IsLike,
})
if err != nil {
c.JSON(http.StatusOK, gin.H{
"code": 500,
"msg": err.Error(),
"tip": "操作失败,请稍后重试",
"data": nil,
})
return
}
if env == nil {
c.JSON(http.StatusOK, gin.H{
"code": 500,
"msg": "empty response",
"tip": "操作失败,请稍后重试",
"data": nil,
})
return
}
c.JSON(http.StatusOK, gin.H{
"code": env.Code,
"msg": env.Msg,
"tip": env.Tip,
"data": env.Data,
})
}