查询书籍评论
()
| 1111 | |
| 1112 | // 查询书籍评论 |
| 1113 | func (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 | |
| 1150 | func (this *CommonController) RelatedBook() { |
| 1151 | bookId := this.getBookIdByIdentify(this.GetString("identify")) |
nothing calls this directly
no test coverage detected