feat: community RPC 从内存存储迁移到 ent 数据库
This commit is contained in:
@@ -3,7 +3,9 @@ package logic
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"time"
|
||||
|
||||
"juwan-backend/app/community/rpc/internal/models/posts"
|
||||
"juwan-backend/app/community/rpc/internal/svc"
|
||||
"juwan-backend/app/community/rpc/pb"
|
||||
|
||||
@@ -29,17 +31,15 @@ func (l *DelPostsLogic) DelPosts(in *pb.DelPostsReq) (*pb.DelPostsResp, error) {
|
||||
return nil, errors.New("id is required")
|
||||
}
|
||||
|
||||
store := l.svcCtx.Store
|
||||
store.Mu.Lock()
|
||||
defer store.Mu.Unlock()
|
||||
|
||||
post, ok := store.Posts[in.GetId()]
|
||||
if !ok {
|
||||
return &pb.DelPostsResp{}, nil
|
||||
now := time.Now()
|
||||
_, err := l.svcCtx.CommunityModelRW.Posts.Update().
|
||||
Where(posts.IDEQ(in.GetId()), posts.DeletedAtIsNil()).
|
||||
SetDeletedAt(now).
|
||||
SetUpdatedAt(now).
|
||||
Save(l.ctx)
|
||||
if err != nil {
|
||||
logx.Errorf("delPosts err: %v", err)
|
||||
}
|
||||
now := nowUnix(0)
|
||||
post.DeletedAt = now
|
||||
post.UpdatedAt = now
|
||||
|
||||
return &pb.DelPostsResp{}, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user