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

Method Star

models/star.go:51–72  ·  view source on GitHub ↗

收藏或者取消收藏 @param uid 用户id @param bid 书籍id @return cancel 是否是取消收藏,只是标记属于取消还是收藏操作,err才表示执行操作成功与否

(uid, bid int)

Source from the content-addressed store, hash-verified

49//@param bid 书籍id
50//@return cancel 是否是取消收藏,只是标记属于取消还是收藏操作,err才表示执行操作成功与否
51func (this *Star) Star(uid, bid int) (cancel bool, err error) {
52 var star = Star{Uid: uid, Bid: bid}
53 o := orm.NewOrm()
54 qs := o.QueryTable("md_star")
55 o.Read(&star, "Uid", "Bid")
56 sc := NewBookCounter()
57 if star.Id > 0 { //取消收藏
58 if _, err = qs.Filter("id", star.Id).Delete(); err == nil {
59 SetIncreAndDecre("md_books", "star", fmt.Sprintf("book_id=%v and star>0", bid), false, 1)
60 sc.Decrease(bid, false)
61 }
62 cancel = true
63 } else { //添加收藏
64 cancel = false
65 star.LastRead = int(time.Now().Unix())
66 if _, err = o.Insert(&star); err == nil { //收藏计数+1
67 SetIncreAndDecre("md_books", "star", "book_id="+strconv.Itoa(bid), true, 1)
68 sc.Increase(bid, false)
69 }
70 }
71 return
72}
73
74//是否收藏了文档
75func (this *Star) DoesStar(uid, bid interface{}) bool {

Callers

nothing calls this directly

Calls 7

DecreaseMethod · 0.95
IncreaseMethod · 0.95
NewBookCounterFunction · 0.85
SetIncreAndDecreFunction · 0.85
ReadMethod · 0.45
DeleteMethod · 0.45
InsertMethod · 0.45

Tested by

no test coverage detected