feat: 更新评论和帖子模型,添加用户信息和原创标识,优化API请求和组件结构

This commit is contained in:
2025-07-28 06:22:07 +08:00
parent 5c20a310e3
commit d73ed493be
20 changed files with 260 additions and 181 deletions

View File

@ -31,7 +31,7 @@ func (cs *CommentService) CreateComment(ctx context.Context, req *dto.CreateComm
UserID: currentUser.ID,
IsPrivate: req.IsPrivate,
}
err := repo.Comment.CreateComment(comment)
if err != nil {
@ -63,7 +63,7 @@ func (cs *CommentService) UpdateComment(ctx context.Context, req *dto.UpdateComm
if err != nil {
return err
}
return nil
}
@ -100,15 +100,15 @@ func (cs *CommentService) GetComment(ctx context.Context, commentID string) (*dt
}
commentDto := dto.CommentDto{
ID: comment.ID,
TargetID: comment.TargetID,
ID: comment.ID,
TargetID: comment.TargetID,
TargetType: comment.TargetType,
Content: comment.Content,
ReplyID: comment.ReplyID,
Depth: comment.Depth,
CreatedAt: comment.CreatedAt.String(),
UpdatedAt: comment.UpdatedAt.String(),
User: *comment.User.ToDto(),
Content: comment.Content,
ReplyID: comment.ReplyID,
Depth: comment.Depth,
CreatedAt: comment.CreatedAt.String(),
UpdatedAt: comment.UpdatedAt.String(),
User: comment.User.ToDto(),
}
return &commentDto, err
@ -132,8 +132,8 @@ func (cs *CommentService) GetCommentList(ctx context.Context, req *dto.GetCommen
TargetType: comment.TargetType,
CreatedAt: comment.CreatedAt.String(),
UpdatedAt: comment.UpdatedAt.String(),
Depth: comment.Depth,
User: *comment.User.ToDto(),
Depth: comment.Depth,
User: comment.User.ToDto(),
}
commentDtos = append(commentDtos, commentDto)
}

View File

@ -76,18 +76,7 @@ func (p *PostService) GetPost(ctx context.Context, id string) (*dto.PostDto, err
if post.IsPrivate && (!ok || post.UserID != currentUser.ID) {
return nil, errs.ErrForbidden
}
return &dto.PostDto{
UserID: post.UserID,
Title: post.Title,
Content: post.Content,
Labels: func() []dto.LabelDto {
labelDtos := make([]dto.LabelDto, 0)
for _, label := range post.Labels {
labelDtos = append(labelDtos, label.ToDto())
}
return labelDtos
}(),
}, nil
return post.ToDto(), nil
}
func (p *PostService) UpdatePost(ctx context.Context, id string, req *dto.CreateOrUpdatePostReq) (uint, error) {
@ -124,8 +113,8 @@ func (p *PostService) UpdatePost(ctx context.Context, id string, req *dto.Create
return post.ID, nil
}
func (p *PostService) ListPosts(ctx context.Context, req *dto.ListPostReq) ([]dto.PostDto, error) {
postDtos := make([]dto.PostDto, 0)
func (p *PostService) ListPosts(ctx context.Context, req *dto.ListPostReq) ([]*dto.PostDto, error) {
postDtos := make([]*dto.PostDto, 0)
currentUserID, _ := ctxutils.GetCurrentUserID(ctx)
posts, err := repo.Post.ListPosts(currentUserID, req.Keywords, req.Page, req.Size, req.OrderBy, req.Desc)
if err != nil {