返回用户对该章节是否已读
()
| 628 | |
| 629 | // 返回用户对该章节是否已读 |
| 630 | func (this *CommonController) BookMenu() { |
| 631 | var ( |
| 632 | book models.Book |
| 633 | o = orm.NewOrm() |
| 634 | ) |
| 635 | identify := this.GetString("identify") |
| 636 | q := o.QueryTable(book) |
| 637 | cols := []string{"book_id", "privately_owned", "member_id"} |
| 638 | if id, _ := strconv.Atoi(identify); id > 0 { |
| 639 | q.Filter("book_id", id).One(&book, cols...) |
| 640 | } else { |
| 641 | q.Filter("identify", identify).One(&book, cols...) |
| 642 | } |
| 643 | |
| 644 | if book.BookId == 0 || (book.PrivatelyOwned == 1 && this.isLogin() != book.MemberId) { |
| 645 | this.Response(http.StatusNotFound, messageNotFound) |
| 646 | } |
| 647 | |
| 648 | docsOri, err := models.NewDocument().FindListByBookId(book.BookId, true) |
| 649 | if err != nil { |
| 650 | beego.Error(err.Error()) |
| 651 | this.Response(http.StatusInternalServerError, messageInternalServerError) |
| 652 | } |
| 653 | |
| 654 | var docs []APIDoc |
| 655 | uid := this.isLogin() |
| 656 | readed := make(map[int]bool) |
| 657 | latestReadId := 0 |
| 658 | if uid > 0 { |
| 659 | lists, _, _ := new(models.ReadRecord).List(uid, book.BookId) |
| 660 | if len(lists) > 0 { |
| 661 | latestReadId = lists[0].DocId |
| 662 | } |
| 663 | for _, item := range lists { |
| 664 | readed[item.DocId] = true |
| 665 | } |
| 666 | } |
| 667 | |
| 668 | for _, item := range docsOri { |
| 669 | var doc APIDoc |
| 670 | utils.CopyObject(item, &doc) |
| 671 | if val, ok := readed[doc.DocumentId]; ok { |
| 672 | doc.Readed = val |
| 673 | } |
| 674 | docs = append(docs, doc) |
| 675 | } |
| 676 | this.Response(http.StatusOK, messageSuccess, map[string]interface{}{"menu": docs, "latest_read_id": latestReadId}) |
| 677 | } |
| 678 | |
| 679 | // 【OK】 |
| 680 | func (this *CommonController) BookLists() { |
nothing calls this directly
no test coverage detected