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,16 +30,12 @@ func (l *GetCommentLikesByIdLogic) GetCommentLikesById(in *pb.GetCommentLikesByI
|
||||
return nil, errors.New("id is required")
|
||||
}
|
||||
|
||||
store := l.svcCtx.Store
|
||||
store.Mu.RLock()
|
||||
defer store.Mu.RUnlock()
|
||||
|
||||
for _, like := range store.CommentLikes {
|
||||
if like.GetCommentId() == in.GetId() {
|
||||
cp := *like
|
||||
return &pb.GetCommentLikesByIdResp{CommentLikes: &cp}, nil
|
||||
}
|
||||
like, err := l.svcCtx.CommunityModelRO.CommentLikes.Query().
|
||||
Where(commentlikes.CommentIDEQ(in.GetId())).
|
||||
First(l.ctx)
|
||||
if err != nil {
|
||||
return nil, errors.New("comment like not found")
|
||||
}
|
||||
return nil, errors.New("comment like not found")
|
||||
|
||||
return &pb.GetCommentLikesByIdResp{CommentLikes: entCommentLikeToPb(like)}, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user