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

Method AddComments

models/comments.go:266–297  ·  view source on GitHub ↗

添加评论

(uid, bookId, pid, docId int, content string)

Source from the content-addressed store, hash-verified

264
265//添加评论
266func (this *Comments) AddComments(uid, bookId, pid, docId int, content string) (err error) {
267 var comment Comments
268
269 //查询该用户现有的评论
270 second := beego.AppConfig.DefaultInt("CommentInterval", 60)
271 now := time.Now()
272 o := orm.NewOrm()
273 o.QueryTable("md_comments").Filter("uid", uid).Filter("TimeCreate__gt", now.Add(-time.Duration(second)*time.Second)).OrderBy("-Id").One(&comment, "Id")
274 if comment.Id > 0 {
275 return fmt.Errorf("您距离上次发表评论时间小于 %v 秒,请歇会儿再发。", second)
276 }
277
278 var comments = Comments{
279 Uid: uid,
280 BookId: bookId,
281 Content: content,
282 TimeCreate: now,
283 DocId: docId,
284 Pid: pid,
285 }
286
287 if _, err = o.Insert(&comments); err != nil {
288 beego.Error(err.Error())
289 err = errors.New("发表评论失败")
290 return
291 }
292 if docId == 0 {
293 // 书籍被评论数量量+1
294 SetIncreAndDecre("md_books", "cnt_comment", fmt.Sprintf("book_id=%v", bookId), true)
295 }
296 return
297}

Callers 2

CommentMethod · 0.80
PostCommentMethod · 0.80

Calls 3

SetIncreAndDecreFunction · 0.85
AddMethod · 0.45
InsertMethod · 0.45

Tested by

no test coverage detected