diff --git a/models/attachment.go b/models/attachment.go index 45f86e8a0..a0cd624b4 100755 --- a/models/attachment.go +++ b/models/attachment.go @@ -70,6 +70,7 @@ type AttachmentsOptions struct { DecompressState int Type int UploaderID int64 + NeedDatasetIDs bool NeedIsPrivate bool IsPrivate bool NeedRepoInfo bool @@ -543,8 +544,7 @@ func Attachments(opts *AttachmentsOptions) ([]*AttachmentInfo, int64, error) { defer sess.Close() var cond = builder.NewCond() - - if len(opts.DatasetIDs) > 0 { + if opts.NeedDatasetIDs { cond = cond.And( builder.In("attachment.dataset_id", opts.DatasetIDs), ) diff --git a/routers/repo/dataset.go b/routers/repo/dataset.go index b3fbbe1dd..014162be6 100755 --- a/routers/repo/dataset.go +++ b/routers/repo/dataset.go @@ -319,12 +319,13 @@ func CurrentRepoDataset(ctx *context.Context) { Page: page, PageSize: setting.UI.IssuePagingNum, }, - Keyword: keyword, - DatasetIDs: datasetIDs, - UploaderID: uploaderID, - Type: cloudbrainType, - NeedIsPrivate: false, - NeedRepoInfo: true, + Keyword: keyword, + NeedDatasetIDs: true, + DatasetIDs: datasetIDs, + UploaderID: uploaderID, + Type: cloudbrainType, + NeedIsPrivate: false, + NeedRepoInfo: true, }) if err != nil { ctx.ServerError("datasets", err) @@ -359,11 +360,12 @@ func MyDatasets(ctx *context.Context) { Page: page, PageSize: setting.UI.IssuePagingNum, }, - Keyword: keyword, - UploaderID: uploaderID, - Type: cloudbrainType, - NeedIsPrivate: false, - NeedRepoInfo: true, + Keyword: keyword, + NeedDatasetIDs: false, + UploaderID: uploaderID, + Type: cloudbrainType, + NeedIsPrivate: false, + NeedRepoInfo: true, }) if err != nil { ctx.ServerError("datasets", err) @@ -397,11 +399,12 @@ func PublicDataset(ctx *context.Context) { Page: page, PageSize: setting.UI.IssuePagingNum, }, - Keyword: keyword, - NeedIsPrivate: true, - IsPrivate: false, - Type: cloudbrainType, - NeedRepoInfo: true, + Keyword: keyword, + NeedDatasetIDs: false, + NeedIsPrivate: true, + IsPrivate: false, + Type: cloudbrainType, + NeedRepoInfo: true, }) if err != nil { ctx.ServerError("datasets", err) @@ -431,45 +434,55 @@ func MyFavoriteDataset(ctx *context.Context) { keyword := strings.Trim(ctx.Query("q"), " ") var datasetIDs []int64 - - datasetStars, err := models.GetDatasetStarByUser(ctx.User) - if err != nil { - ctx.JSON(http.StatusOK, models.BaseErrorMessage(ctx.Tr("GetDatasetByRepo failed", err))) - } - 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, - 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()) + if !ctx.IsSigned { + log.Error("user not login!") ctx.JSON(200, map[string]string{ "result_code": "-1", - "error_msg": err.Error(), + "error_msg": "user not login!", "data": "", }) return + } else { + datasetStars, err := models.GetDatasetStarByUser(ctx.User) + if err != nil { + ctx.JSON(http.StatusOK, models.BaseErrorMessage(ctx.Tr("GetDatasetStarByUser failed", err))) + } + 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 + } + + 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 + } + ctx.JSON(200, map[string]string{ + "result_code": "0", + "data": string(data), + "count": strconv.FormatInt(count, 10), + }) } - ctx.JSON(200, map[string]string{ - "result_code": "0", - "data": string(data), - "count": strconv.FormatInt(count, 10), - }) }