diff options
author | Unknown <joe2010xtmf@163.com> | 2014-03-26 16:41:16 -0400 |
---|---|---|
committer | Unknown <joe2010xtmf@163.com> | 2014-03-26 16:41:16 -0400 |
commit | dd6246877d8dd2de5f71f51c58a90eb155785c34 (patch) | |
tree | 12cd46c291c2e2adf61eeccb638b771a66761d52 /models/issue.go | |
parent | 4b9eef50c9bf91e6ca2d85d9e63dc69b0ffba737 (diff) | |
download | gitea-dd6246877d8dd2de5f71f51c58a90eb155785c34.tar.gz gitea-dd6246877d8dd2de5f71f51c58a90eb155785c34.zip |
Almost done diff page
Diffstat (limited to 'models/issue.go')
-rw-r--r-- | models/issue.go | 25 |
1 files changed, 17 insertions, 8 deletions
diff --git a/models/issue.go b/models/issue.go index 47ec4edd0b..97e51a0c58 100644 --- a/models/issue.go +++ b/models/issue.go @@ -173,14 +173,23 @@ type Comment struct { // CreateComment creates comment of issue or commit. func CreateComment(userId, issueId, commitId, line int64, content string) error { - _, err := orm.Insert(&Comment{ - PosterId: userId, - IssueId: issueId, - CommitId: commitId, - Line: line, - Content: content, - }) - return err + sess := orm.NewSession() + defer sess.Close() + sess.Begin() + + if _, err := orm.Insert(&Comment{PosterId: userId, IssueId: issueId, + CommitId: commitId, Line: line, Content: content, + }); err != nil { + sess.Rollback() + return err + } + + rawSql := "UPDATE `issue` SET num_comments = num_comments + 1 WHERE id = ?" + if _, err := sess.Exec(rawSql, issueId); err != nil { + sess.Rollback() + return err + } + return sess.Commit() } // GetIssueComments returns list of comment by given issue id. |