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,32 +30,23 @@ func (l *UpdateCommentsLogic) UpdateComments(in *pb.UpdateCommentsReq) (*pb.Upda
|
||||
return nil, errors.New("id is required")
|
||||
}
|
||||
|
||||
store := l.svcCtx.Store
|
||||
store.Mu.Lock()
|
||||
defer store.Mu.Unlock()
|
||||
updater := l.svcCtx.CommunityModelRW.Comments.Update().
|
||||
Where(comments.IDEQ(in.GetId()), comments.DeletedAtIsNil())
|
||||
|
||||
comment, ok := store.Comments[in.GetId()]
|
||||
if !ok || comment.GetDeletedAt() > 0 {
|
||||
return nil, errors.New("comment not found")
|
||||
}
|
||||
|
||||
if in.GetPostId() > 0 {
|
||||
comment.PostId = in.GetPostId()
|
||||
}
|
||||
if in.GetAuthorId() > 0 {
|
||||
comment.AuthorId = in.GetAuthorId()
|
||||
}
|
||||
if in.GetContent() != "" {
|
||||
comment.Content = in.GetContent()
|
||||
updater = updater.SetContent(in.GetContent())
|
||||
}
|
||||
if in.GetLikeCount() > 0 {
|
||||
comment.LikeCount = in.GetLikeCount()
|
||||
updater = updater.SetLikeCount(int(in.GetLikeCount()))
|
||||
}
|
||||
if in.GetDeletedAt() > 0 {
|
||||
comment.DeletedAt = in.GetDeletedAt()
|
||||
|
||||
n, err := updater.Save(l.ctx)
|
||||
if err != nil {
|
||||
logx.Errorf("updateComments err: %v", err)
|
||||
return nil, errors.New("update comment failed")
|
||||
}
|
||||
if in.GetCreatedAt() > 0 {
|
||||
comment.CreatedAt = in.GetCreatedAt()
|
||||
if n == 0 {
|
||||
return nil, errors.New("comment not found")
|
||||
}
|
||||
|
||||
return &pb.UpdateCommentsResp{}, nil
|
||||
|
||||
Reference in New Issue
Block a user