MCPcopy Index your code
hub / github.com/TruthHun/BookStack / Lists

Method Lists

models/submit_books.go:61–94  ·  view source on GitHub ↗
(page, size int, status ...bool)

Source from the content-addressed store, hash-verified

59}
60
61func (m *SubmitBooks) Lists(page, size int, status ...bool) (books []SubmitBooks, total int64, err error) {
62 o := orm.NewOrm()
63 q := o.QueryTable(m)
64 where := ""
65 if len(status) > 0 {
66 q = q.Filter("status", status[0])
67 if status[0] == true {
68 where = " where status = 1 "
69 } else {
70 where = "where status = 0 "
71 }
72 }
73 total, err = q.Count()
74 if err != nil {
75 beego.Error(err)
76 return
77 }
78 if total == 0 {
79 return
80 }
81
82 querySQL := fmt.Sprintf("select b.*,u.nickname,u.account from md_submit_books b left join md_members u on u.member_id = b.uid %v order by b.id desc limit %v offset %v",
83 where, size, (page-1)*size,
84 )
85 _, err = o.Raw(querySQL).QueryRows(&books)
86 if err != nil {
87 beego.Error(err.Error())
88 }
89 for idx, book := range books {
90 book.CreatedAtStr = book.CreatedAt.Format("2006-01-02 15:04:05")
91 books[idx] = book
92 }
93 return
94}

Callers 1

SubmitBookMethod · 0.95

Calls 1

CountMethod · 0.45

Tested by

no test coverage detected