Skip to content

Commit 7b86fed

Browse files
committed
feat:support reply comment
1 parent 7ac4239 commit 7b86fed

File tree

5 files changed

+31
-6
lines changed

5 files changed

+31
-6
lines changed

repository/comment_repo.go

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,25 @@ func (r *commentRepository) GetCommentsByCursorTime(db *gorm.DB, articleID int64
3333
return comments, err
3434
}
3535

36+
func (r *commentRepository) GetCommentsByCommentID(db *gorm.DB, id int64) (*model.Comment, error) {
37+
return r.takeOne(db, "id = ?", id)
38+
}
39+
3640
func (r *commentRepository) GetCommentsByArticleID(db *gorm.DB, articleID int64) ([]model.Comment, error) {
37-
return r.take(db, "article_id = ?", articleID)
41+
return r.takeList(db, "article_id = ?", articleID)
42+
}
43+
44+
func (r *commentRepository) takeOne(db *gorm.DB, column string, value interface{}) (*model.Comment, error) {
45+
comment := &model.Comment{}
46+
err := db.Where(column, value).Find(&comment).Error
47+
if err != nil {
48+
logs.Logger.Errorf("query db error:", err)
49+
return nil, err
50+
}
51+
return comment, nil
3852
}
3953

40-
func (r *commentRepository) take(db *gorm.DB, column string, value interface{}) ([]model.Comment, error) {
54+
func (r *commentRepository) takeList(db *gorm.DB, column string, value interface{}) ([]model.Comment, error) {
4155
var comments []model.Comment
4256
err := db.Where(column, value).Find(&comments).Error
4357
if err != nil {

service/comments.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,13 @@ func buildCommentInfo(comment *model.Comment) *model.CommentInfo {
7676
LikeCount: comment.LikeCount,
7777
CreateTime: comment.CreateTime,
7878
}
79+
if comment.ParentID > 0 {
80+
parentComment, err := repository.CommentRepository.GetCommentsByCommentID(util.DB(), comment.ParentID)
81+
if err != nil {
82+
logs.Logger.Errorf("查询父评论信息出错")
83+
}
84+
commentInfo.ParentComment = buildCommentInfo(parentComment)
85+
}
7986
return commentInfo
8087
}
8188

site/components/CommentInput.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<div ref="commentEditor" class="comment-input-wrapper">
55
<div v-if="quote" class="comment-quote-info">
66
回复:
7-
<label v-text="quote.user.nickname" />
7+
<label v-text="quote.user_nickname" />
88
<i class="iconfont icon-close" alt="取消回复" @click="cancelReply" />
99
</div>
1010
<markdown-editor

site/components/LoadMoreComments.vue

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,6 @@ export default {
6565
const ret = await this.$axios.get(this.url, {
6666
params: _params,
6767
})
68-
console.log(ret)
6968
this.cursor = ret.cursor
7069
if (ret.comment_list && ret.total_num) {
7170
ret.comment_list.forEach((item) => {

site/pages/topic/_id.vue

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,8 @@ export default {
231231
return {
232232
topic,
233233
commentsPage,
234+
liked: false,
235+
favorited: false,
234236
}
235237
},
236238
computed: {
@@ -273,9 +275,12 @@ export default {
273275
if (this.liked) {
274276
return
275277
}
276-
await this.$axios.post('/api/topic/like/' + topic.topicId)
278+
await this.$axios.post('/api/topics/like', {
279+
article_id: topic.article_id,
280+
user_id: this.$store.state.user.current.id,
281+
})
277282
this.liked = true
278-
topic.likeCount++
283+
topic.like_count++
279284
this.likeUsers = this.likeUsers || []
280285
this.likeUsers.unshift(this.$store.state.user.current)
281286
} catch (e) {

0 commit comments

Comments
 (0)