forked from mindoc-org/mindoc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
comment_result.go
39 lines (28 loc) · 1 KB
/
comment_result.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
package models
import "github.com/beego/beego/v2/client/orm"
type CommentResult struct {
Comment
Author string `json:"author"`
ReplyAccount string `json:"reply_account"`
}
func (m *CommentResult) FindForDocumentToPager(doc_id, page_index, page_size int) (comments []*CommentResult, totalCount int, err error) {
o := orm.NewOrm()
sql1 := `
SELECT
comment.* ,
parent.* ,
mdmb.account AS author,
p_member.account AS reply_account
FROM md_comments AS comment
LEFT JOIN md_members AS mdmb ON comment.member_id = mdmb.member_id
LEFT JOIN md_comments AS parent ON comment.parent_id = parent.comment_id
LEFT JOIN md_members AS p_member ON p_member.member_id = parent.member_id
WHERE comment.document_id = ? ORDER BY comment.comment_id DESC LIMIT 0,10`
offset := (page_index - 1) * page_size
_, err = o.Raw(sql1, doc_id, offset, page_size).QueryRows(&comments)
v, err := o.QueryTable(m.TableNameWithPrefix()).Filter("document_id", doc_id).Count()
if err == nil {
totalCount = int(v)
}
return
}