Browse Source

fix-bug

tags/v1.22.3.2^2
liuzx 3 years ago
parent
commit
b8a097b598
2 changed files with 66 additions and 53 deletions
  1. +2
    -2
      models/attachment.go
  2. +64
    -51
      routers/repo/dataset.go

+ 2
- 2
models/attachment.go View File

@@ -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),
)


+ 64
- 51
routers/repo/dataset.go View File

@@ -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),
})
}

Loading…
Cancel
Save