MCPcopy Create free account
hub / github.com/GoSimplicity/LinkMe / FindCommentByCommentId

Method FindCommentByCommentId

internal/repository/dao/comment.go:69–81  ·  view source on GitHub ↗

FindCommentByCommentId 根据commentId查找评论

(ctx context.Context, commentId int64)

Source from the content-addressed store, hash-verified

67
68// FindCommentByCommentId 根据commentId查找评论
69func (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}
82func (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 {

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected