Initial commit: web_hghl_server

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
2026-10-26 16:28:14 +08:00
co-authored by Claude Opus 4.7
commit 65fca60622
653 changed files with 135901 additions and 0 deletions
+63
View File
@@ -0,0 +1,63 @@
package commentser
import (
"context"
"videoweb/app/api/proto"
"videoweb/pub/common/enum/redisconst"
"videoweb/pub/common/log"
"videoweb/pub/common/srvdef"
"videoweb/pub/models/commentlikemod"
"videoweb/pub/models/commentmod"
"videoweb/pub/redis"
"go.mongodb.org/mongo-driver/bson"
)
// SetCommentLike 设置评论点赞状态
func SetCommentLike(ctx context.Context, userId int64, req *proto.CommentLikeSetReq) (*proto.CommentLikeSetResp, *srvdef.SrvErr) {
if userId <= 0 || req == nil || req.CommentId <= 0 || req.IsLike == nil {
return nil, srvdef.New(srvdef.ErrParamError, "", "")
}
comment, err := commentmod.FindOneComment(ctx, bson.M{
commentmod.FN.Comment.Id: req.CommentId,
commentmod.FN.Comment.ReviewStatus: 1,
})
if err != nil {
return nil, err
}
var changed bool
if *req.IsLike {
changed, err = commentlikemod.Add(ctx, userId, req.CommentId)
} else {
changed, err = commentlikemod.Remove(ctx, userId, req.CommentId)
}
if err != nil {
return nil, err
}
count := comment.CountLike
if changed {
delta := int64(1)
if !*req.IsLike {
delta = -1
}
count, err = commentmod.ChangeLikeCount(ctx, req.CommentId, delta)
if err != nil {
if *req.IsLike {
_, _ = commentlikemod.Remove(ctx, userId, req.CommentId)
} else {
_, _ = commentlikemod.Add(ctx, userId, req.CommentId)
}
return nil, err
}
} else {
current, findErr := commentmod.FindOneComment(ctx, bson.M{commentmod.FN.Comment.Id: req.CommentId})
if findErr != nil {
return nil, findErr
}
count = current.CountLike
}
if cacheErr := redis.Del(redisconst.CommentListCacheKey(comment.ObjectId, comment.ObjectType)); cacheErr != nil {
log.Warn("SetCommentLike clear cache", log.E(cacheErr))
}
return &proto.CommentLikeSetResp{CommentId: req.CommentId, IsLike: *req.IsLike, CountLike: count}, nil
}