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

Method BookListsByCids

controllers/api/CommonController.go:715–761  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

713}
714
715func (this *CommonController) BookListsByCids() {
716 sort := this.GetString("sort", "new") // new、recommend、hot、pin
717 page, _ := this.GetInt("page", 1)
718 lang := this.GetString("lang")
719 size, _ := this.GetInt("size", 10)
720 cids := this.GetString("cids")
721
722 var cidArr []int
723 slice := strings.Split(cids, ",")
724 for _, item := range slice {
725 if cid, _ := strconv.Atoi(strings.TrimSpace(item)); cid > 0 {
726 cidArr = append(cidArr, cid)
727 }
728 }
729
730 if len(cidArr) == 0 {
731 this.Response(http.StatusBadRequest, messageBadRequest)
732 }
733
734 if page <= 0 {
735 page = 1
736 }
737
738 size = utils.RangeNumber(size, 5, maxPageSize)
739
740 model := models.NewBook()
741
742 fields := []string{"book_id", "book_name", "identify", "order_index", "description", "label", "doc_count",
743 "vcnt", "star", "lang", "cover", "score", "cnt_score", "cnt_comment", "modify_time", "create_time", "release_time",
744 }
745 data := make(map[int]interface{})
746 for _, cid := range cidArr {
747 books, _, _ := model.HomeData(page, size, models.BookOrder(sort), lang, cid, fields...)
748 if len(books) > 0 {
749 var lists []APIBook
750 var list APIBook
751 for _, book := range books {
752 book.Cover = this.completeLink(utils.ShowImg(book.Cover, "cover"))
753 utils.CopyObject(&book, &list)
754 lists = append(lists, list)
755 }
756 data[cid] = lists
757 }
758 }
759
760 this.Response(http.StatusOK, messageSuccess, map[string]interface{}{"books": data})
761}
762
763func (this *CommonController) Read() {
764 identify := this.GetString("identify")

Callers

nothing calls this directly

Calls 9

HomeDataMethod · 0.95
RangeNumberFunction · 0.92
NewBookFunction · 0.92
BookOrderTypeAlias · 0.92
ShowImgFunction · 0.92
CopyObjectFunction · 0.92
ResponseMethod · 0.80
completeLinkMethod · 0.80
appendFunction · 0.50

Tested by

no test coverage detected