feat: community RPC 从内存存储迁移到 ent 数据库
This commit is contained in:
@@ -4,6 +4,7 @@ import (
|
||||
"context"
|
||||
"errors"
|
||||
|
||||
"juwan-backend/app/community/rpc/internal/models/comments"
|
||||
"juwan-backend/app/community/rpc/internal/svc"
|
||||
"juwan-backend/app/community/rpc/pb"
|
||||
|
||||
@@ -29,15 +30,12 @@ func (l *GetCommentsByIdLogic) GetCommentsById(in *pb.GetCommentsByIdReq) (*pb.G
|
||||
return nil, errors.New("id is required")
|
||||
}
|
||||
|
||||
store := l.svcCtx.Store
|
||||
store.Mu.RLock()
|
||||
defer store.Mu.RUnlock()
|
||||
|
||||
comment, ok := store.Comments[in.GetId()]
|
||||
if !ok || comment.GetDeletedAt() > 0 {
|
||||
comment, err := l.svcCtx.CommunityModelRO.Comments.Query().
|
||||
Where(comments.IDEQ(in.GetId()), comments.DeletedAtIsNil()).
|
||||
First(l.ctx)
|
||||
if err != nil {
|
||||
return nil, errors.New("comment not found")
|
||||
}
|
||||
out := *comment
|
||||
|
||||
return &pb.GetCommentsByIdResp{Comments: &out}, nil
|
||||
return &pb.GetCommentsByIdResp{Comments: entCommentToPb(comment)}, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user