FindCommentByCommentId 根据commentId查找评论
(ctx context.Context, commentId int64)
| 67 | |
| 68 | // FindCommentByCommentId 根据commentId查找评论 |
| 69 | func (c *commentDAO) FindCommentByCommentId(ctx context.Context, commentId int64) (Comment, error) { |
| 70 | // 先查找评论是否存在 |
| 71 | var comment Comment |
| 72 | if err := c.db.WithContext(ctx).First(&comment, "id = ?", commentId).Error; err != nil { |
| 73 | if errors.Is(err, gorm.ErrRecordNotFound) { |
| 74 | c.l.Error("评论不存在", zap.Int64("commentId", commentId), zap.Error(err)) |
| 75 | return Comment{}, fmt.Errorf("评论不存在") |
| 76 | } |
| 77 | c.l.Error("查找评论失败", zap.Error(err)) |
| 78 | return Comment{}, err |
| 79 | } |
| 80 | return comment, nil |
| 81 | } |
| 82 | func (c *commentDAO) UpdateComment(ctx context.Context, comment Comment) error { |
| 83 | // 确保更新的是指定 ID 的评论 |
| 84 | if err := c.db.WithContext(ctx).Model(&Comment{}).Where("id = ?", comment.Id).Updates(comment).Error; err != nil { |
nothing calls this directly
no outgoing calls
no test coverage detected