feat: community RPC 从内存存储迁移到 ent 数据库
This commit is contained in:
@@ -4,6 +4,7 @@ import (
|
||||
"context"
|
||||
"errors"
|
||||
|
||||
"juwan-backend/app/community/rpc/internal/models/commentlikes"
|
||||
"juwan-backend/app/community/rpc/internal/svc"
|
||||
"juwan-backend/app/community/rpc/pb"
|
||||
|
||||
@@ -29,18 +30,19 @@ func (l *UpdateCommentLikesLogic) UpdateCommentLikes(in *pb.UpdateCommentLikesRe
|
||||
return nil, errors.New("commentId and userId are required")
|
||||
}
|
||||
|
||||
store := l.svcCtx.Store
|
||||
store.Mu.Lock()
|
||||
defer store.Mu.Unlock()
|
||||
|
||||
if _, ok := store.Comments[in.GetCommentId()]; !ok {
|
||||
return nil, errors.New("comment not found")
|
||||
_, err := l.svcCtx.CommunityModelRO.CommentLikes.Query().
|
||||
Where(commentlikes.CommentIDEQ(in.GetCommentId()), commentlikes.UserIDEQ(in.GetUserId())).
|
||||
First(l.ctx)
|
||||
if err != nil {
|
||||
return nil, errors.New("comment like not found")
|
||||
}
|
||||
key := commentLikeKey(in.GetCommentId(), in.GetUserId())
|
||||
store.CommentLikes[key] = &pb.CommentLikes{
|
||||
CommentId: in.GetCommentId(),
|
||||
UserId: in.GetUserId(),
|
||||
CreatedAt: nowUnix(in.GetCreatedAt()),
|
||||
|
||||
_, err = l.svcCtx.CommunityModelRW.CommentLikes.Update().
|
||||
Where(commentlikes.CommentIDEQ(in.GetCommentId()), commentlikes.UserIDEQ(in.GetUserId())).
|
||||
Save(l.ctx)
|
||||
if err != nil {
|
||||
logx.Errorf("updateCommentLikes err: %v", err)
|
||||
return nil, errors.New("update comment like failed")
|
||||
}
|
||||
|
||||
return &pb.UpdateCommentLikesResp{}, nil
|
||||
|
||||
Reference in New Issue
Block a user