feat: 迁移plant
This commit is contained in:
@@ -3,6 +3,7 @@ package logic
|
||||
import (
|
||||
"context"
|
||||
|
||||
plantModel "sundynix-micro-go/app/plant/model"
|
||||
"sundynix-micro-go/app/plant/rpc/internal/svc"
|
||||
"sundynix-micro-go/app/plant/rpc/plant"
|
||||
|
||||
@@ -23,8 +24,37 @@ func NewGetPostDetailLogic(ctx context.Context, svcCtx *svc.ServiceContext) *Get
|
||||
}
|
||||
}
|
||||
|
||||
// 帖子详情
|
||||
func (l *GetPostDetailLogic) GetPostDetail(in *plant.IdReq) (*plant.PostDetailResp, error) {
|
||||
// todo: add your logic here and delete this line
|
||||
var post plantModel.Post
|
||||
if err := l.svcCtx.DB.Where("id = ?", in.Id).First(&post).Error; err != nil {
|
||||
return nil, err
|
||||
}
|
||||
var comments []plantModel.PostComment
|
||||
l.svcCtx.DB.Where("post_id = ?", in.Id).Order("created_at asc").Find(&comments)
|
||||
|
||||
return &plant.PostDetailResp{}, nil
|
||||
var commentInfos []*plant.PostCommentInfo
|
||||
for _, c := range comments {
|
||||
commentInfos = append(commentInfos, &plant.PostCommentInfo{
|
||||
Id: c.ID,
|
||||
UserId: c.UserID,
|
||||
Content: c.Content,
|
||||
ParentId: c.ParentID,
|
||||
CreatedAt: c.CreatedAt.Unix(),
|
||||
})
|
||||
}
|
||||
return &plant.PostDetailResp{
|
||||
Post: &plant.PostInfo{
|
||||
Id: post.ID,
|
||||
UserId: post.UserID,
|
||||
Title: post.Title,
|
||||
Content: post.Content,
|
||||
ViewCount: int32(post.ViewCount),
|
||||
CommentCount: int32(post.CommentCount),
|
||||
LikeCount: int32(post.LikeCount),
|
||||
Location: post.Location,
|
||||
CreatedAt: post.CreatedAt.Unix(),
|
||||
},
|
||||
Comments: commentInfos,
|
||||
}, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user