From 4b9eef50c9bf91e6ca2d85d9e63dc69b0ffba737 Mon Sep 17 00:00:00 2001 From: Unknown Date: Wed, 26 Mar 2014 12:31:01 -0400 Subject: Add comment of issue --- models/issue.go | 22 +++++++++++++++++++++- models/models.go | 2 +- 2 files changed, 22 insertions(+), 2 deletions(-) (limited to 'models') diff --git a/models/issue.go b/models/issue.go index 2de65685..47ec4edd 100644 --- a/models/issue.go +++ b/models/issue.go @@ -163,9 +163,29 @@ type Milestone struct { type Comment struct { Id int64 PosterId int64 + Poster *User `xorm:"-"` IssueId int64 CommitId int64 - Line int + Line int64 Content string Created time.Time `xorm:"created"` } + +// 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 +} + +// GetIssueComments returns list of comment by given issue id. +func GetIssueComments(issueId int64) ([]Comment, error) { + comments := make([]Comment, 0, 10) + err := orm.Asc("created").Find(&comments, &Comment{IssueId: issueId}) + return comments, err +} diff --git a/models/models.go b/models/models.go index ad19a929..813725be 100644 --- a/models/models.go +++ b/models/models.go @@ -72,7 +72,7 @@ func setEngine() { func NewEngine() { setEngine() if err := orm.Sync(new(User), new(PublicKey), new(Repository), new(Watch), - new(Action), new(Access), new(Issue)); err != nil { + new(Action), new(Access), new(Issue), new(Comment)); err != nil { fmt.Printf("sync database struct error: %v\n", err) os.Exit(2) } -- cgit v1.2.3