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

Method GetComments

controllers/api/CommonController.go:1113–1148  ·  view source on GitHub ↗

查询书籍评论

()

Source from the content-addressed store, hash-verified

1111
1112// 查询书籍评论
1113func (this *CommonController) GetComments() {
1114 page, _ := this.GetInt("page", 1)
1115 if page <= 0 {
1116 page = 1
1117 }
1118 size, _ := this.GetInt("size", 10)
1119 size = utils.RangeNumber(size, 10, maxPageSize)
1120
1121 bookId := this.getBookIdByIdentify(this.GetString("identify"))
1122 if bookId <= 0 {
1123 this.Response(http.StatusBadRequest, messageBadRequest)
1124 }
1125
1126 uid := this.isLogin()
1127 myScore := 0
1128 if uid > 0 {
1129 myScore = new(models.Score).BookScoreByUid(uid, bookId) / 10
1130 }
1131 comments, err := new(models.Comments).Comments(page, size, models.CommentOpt{BookId: bookId, Status: []int{1}, WithoutDocComment: true})
1132 if err != nil {
1133 beego.Error(err.Error())
1134 }
1135 data := map[string]interface{}{
1136 "my_score": myScore,
1137 "comments": []string{},
1138 }
1139
1140 if len(comments) > 0 {
1141 for idx, _ := range comments {
1142 comments[idx].Avatar = this.completeLink(utils.ShowImg(comments[idx].Avatar, "avatar"))
1143 }
1144 data["comments"] = comments
1145 }
1146
1147 this.Response(http.StatusOK, messageSuccess, data)
1148}
1149
1150func (this *CommonController) RelatedBook() {
1151 bookId := this.getBookIdByIdentify(this.GetString("identify"))

Callers

nothing calls this directly

Calls 8

RangeNumberFunction · 0.92
ShowImgFunction · 0.92
getBookIdByIdentifyMethod · 0.80
ResponseMethod · 0.80
isLoginMethod · 0.80
BookScoreByUidMethod · 0.80
completeLinkMethod · 0.80
CommentsMethod · 0.45

Tested by

no test coverage detected