diff --git a/routers/repo/dataset.go b/routers/repo/dataset.go index 546706419..c51194965 100755 --- a/routers/repo/dataset.go +++ b/routers/repo/dataset.go @@ -433,63 +433,53 @@ func MyFavoriteDataset(ctx *context.Context) { cloudbrainType := ctx.QueryInt("type") keyword := strings.Trim(ctx.Query("q"), " ") - var datasetIDs []int64 - if !ctx.IsSigned { - log.Error("user not login!") + datasetStars, err := models.GetDatasetStarByUser(ctx.User) + if err != nil { + ctx.JSON(http.StatusOK, models.BaseErrorMessage(ctx.Tr("GetDatasetStarByUser failed", err))) + log.Error("GetDatasetStarByUser failed:", err.Error()) ctx.JSON(200, map[string]string{ "result_code": "-1", - "error_msg": "user not login!", + "error_msg": err.Error(), "data": "", }) return - } else { - datasetStars, err := models.GetDatasetStarByUser(ctx.User) - if err != nil { - ctx.JSON(http.StatusOK, models.BaseErrorMessage(ctx.Tr("GetDatasetStarByUser failed", err))) - log.Error("GetDatasetStarByUser failed:", err.Error()) - ctx.JSON(200, map[string]string{ - "result_code": "-1", - "error_msg": err.Error(), - "data": "", - }) - return - } - for i, _ := range datasetStars { - datasetIDs = append(datasetIDs, datasetStars[i].DatasetID) - } + } + for i, _ := range datasetStars { + datasetIDs = append(datasetIDs, datasetStars[i].DatasetID) + } - datasets, count, err := models.Attachments(&models.AttachmentsOptions{ - ListOptions: models.ListOptions{ - Page: page, - PageSize: setting.UI.IssuePagingNum, - }, - Keyword: keyword, - NeedDatasetIDs: true, - DatasetIDs: datasetIDs, - NeedIsPrivate: true, - IsPrivate: false, - Type: cloudbrainType, - NeedRepoInfo: true, - }) - if err != nil { - ctx.ServerError("datasets", err) - return - } + datasets, count, err := models.Attachments(&models.AttachmentsOptions{ + ListOptions: models.ListOptions{ + Page: page, + PageSize: setting.UI.IssuePagingNum, + }, + Keyword: keyword, + NeedDatasetIDs: true, + DatasetIDs: datasetIDs, + NeedIsPrivate: true, + IsPrivate: false, + Type: cloudbrainType, + NeedRepoInfo: true, + }) + if err != nil { + ctx.ServerError("datasets", err) + return + } - data, err := json.Marshal(datasets) - if err != nil { - log.Error("json.Marshal failed:", err.Error()) - ctx.JSON(200, map[string]string{ - "result_code": "-1", - "error_msg": err.Error(), - "data": "", - }) - return - } + data, err := json.Marshal(datasets) + if err != nil { + log.Error("json.Marshal failed:", err.Error()) ctx.JSON(200, map[string]string{ - "result_code": "0", - "data": string(data), - "count": strconv.FormatInt(count, 10), + "result_code": "-1", + "error_msg": err.Error(), + "data": "", }) + return } + ctx.JSON(200, map[string]string{ + "result_code": "0", + "data": string(data), + "count": strconv.FormatInt(count, 10), + }) + }