diff options
author | Unknwon <u@gogs.io> | 2016-07-26 02:48:17 +0800 |
---|---|---|
committer | Unknwon <u@gogs.io> | 2016-07-26 02:48:17 +0800 |
commit | 899e7994595f5fc500de8cdf39e1b737f9f00982 (patch) | |
tree | 1477940293968f1ee2781e04209b7038e9774d95 /models | |
parent | 2295fafb34e2467f3b380a4db8832aa2c70ecc5a (diff) | |
download | gitea-899e7994595f5fc500de8cdf39e1b737f9f00982.tar.gz gitea-899e7994595f5fc500de8cdf39e1b737f9f00982.zip |
#1601 support delete issue comment
Diffstat (limited to 'models')
-rw-r--r-- | models/issue_comment.go | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/models/issue_comment.go b/models/issue_comment.go index faa257789a..e9857b4216 100644 --- a/models/issue_comment.go +++ b/models/issue_comment.go @@ -345,3 +345,29 @@ func UpdateComment(c *Comment) error { _, err := x.Id(c.ID).AllCols().Update(c) return err } + +// DeleteCommentByID deletes a comment by given ID. +func DeleteCommentByID(id int64) error { + comment, err := GetCommentByID(id) + if err != nil { + return err + } + + sess := x.NewSession() + defer sessionRelease(sess) + if err = sess.Begin(); err != nil { + return err + } + + if _, err = sess.Id(comment.ID).Delete(new(Comment)); err != nil { + return err + } + + if comment.Type == COMMENT_TYPE_COMMENT { + if _, err = sess.Exec("UPDATE `issue` SET num_comments = num_comments - 1 WHERE id = ?", comment.IssueID); err != nil { + return err + } + } + + return sess.Commit() +} |