kobe6258 1 Minggu lalu
induk
melakukan
6a0db001c8
2 mengubah file dengan 14 tambahan dan 21 penghapusan
  1. 5 3
      common/exception/exc_enums.go
  2. 9 18
      controllers/user/bookmark_controller.go

+ 5 - 3
common/exception/exc_enums.go

@@ -172,6 +172,7 @@ const (
 	IllegalSourceType
 	IllegalSourceId
 	BookMarkFailed
+	BookMarkListFailed
 )
 
 // ErrorMap 用于存储错误码和错误信息的映射
@@ -290,9 +291,10 @@ var ErrorMap = map[int]string{
 	RefundDealFail:           "处理退款应答失败",
 
 	//收藏
-	IllegalSourceType: "非法的资源类型",
-	IllegalSourceId:   "非法的资源ID",
-	BookMarkFailed:    "收藏失败",
+	IllegalSourceType:  "非法的资源类型",
+	IllegalSourceId:    "非法的资源ID",
+	BookMarkFailed:     "收藏失败",
+	BookMarkListFailed: "获取收藏列表失败",
 }
 
 func Equals(code int, message string) bool {

+ 9 - 18
controllers/user/bookmark_controller.go

@@ -254,27 +254,18 @@ func (bk *BookMarkController) SearchBookMark(sourceType string, key string) {
 		}
 		pageRes.Total = bk.PageInfo.Total
 		pageRes.TotalPage = page.TotalPages(pageRes.Total, pageRes.PageSize)
-		var bookMarkList userService.BookMarkInterface
+		var bookMarkList []userService.BookMarkInterface
 		bookMarkList, err = user.SearchBookMark(key, sourceType, sourceIds, bk.PageInfo, userInfo.Id)
-		switch sourceType {
-		case Chart:
-			var list []userService.BookMarkChart
-			list, err = getChartList(bk.PageInfo, userInfo.Id)
-			if err != nil {
-				err = exception.NewWithException(exception.GetBookMarkListFailed, err.Error())
-				bk.FailedResult("分页查询收藏列表失败", result)
-				return
-			}
-			bookMarks := new(page.PageResult)
-			bookMarks.Data = list
-			bookMarks.Page = pageRes
-			bk.SuccessResult("分页查询收藏列表成功", bookMarks, result)
-			return
-		default:
-			err = exception.New(exception.IllegalSourceType)
-			bk.FailedResult("分页查询收藏列表失败", result)
+		if err != nil {
+			err = exception.New(exception.BookMarkListFailed)
+			bk.FailedResult("分页搜索收藏列表失败", result)
 			return
 		}
+		bookMarks := new(page.PageResult)
+		bookMarks.Data = bookMarkList
+		bookMarks.Page = pageRes
+		bk.SuccessResult("分页搜索收藏列表成功", bookMarks, result)
+		return
 	})
 }