Browse Source

数据集广场协作者

tags/v1.22.6.1^2
ychao_1983 3 years ago
parent
commit
0c5a600190
2 changed files with 22 additions and 0 deletions
  1. +15
    -0
      models/dataset.go
  2. +7
    -0
      routers/home.go

+ 15
- 0
models/dataset.go View File

@@ -107,6 +107,7 @@ type SearchDatasetOptions struct {
Category string
Task string
License string
DatasetIDs []int64
ListOptions
SearchOrderBy
IsOwner bool
@@ -177,6 +178,12 @@ func SearchDatasetCondition(opts *SearchDatasetOptions) builder.Cond {
}
}

if len(opts.DatasetIDs) > 0 {
subCon := builder.NewCond()
subCon = subCon.And(builder.In("dataset.id", opts.DatasetIDs))
cond = cond.Or(subCon)
}

return cond
}

@@ -447,3 +454,11 @@ func IncreaseDownloadCount(datasetID int64) error {

return nil
}

func GetCollaboratorDatasetIdsByUserID(userID int64) []int64 {
var datasets []int64
_ = x.Table("dataset").Join("INNER", "collaboration", "dataset.repo_id = collaboration.repo_id and collaboration.mode>0 and collaboration.user_id=?", userID).
Cols("dataset.id").Find(&datasets)
return datasets

}

+ 7
- 0
routers/home.go View File

@@ -343,6 +343,12 @@ func ExploreDatasets(ctx *context.Context) {
if ctx.User != nil && !ctx.User.IsAdmin {
ownerID = ctx.User.ID
}
var datasetsIds []int64
if ownerID > 0 {

datasetsIds = models.GetCollaboratorDatasetIdsByUserID(ownerID)
}

opts := &models.SearchDatasetOptions{
Keyword: keyword,
IncludePublic: true,
@@ -351,6 +357,7 @@ func ExploreDatasets(ctx *context.Context) {
Task: task,
License: license,
OwnerID: ownerID,
DatasetIDs: datasetsIds,
RecommendOnly: ctx.QueryBool("recommend"),
ListOptions: models.ListOptions{
Page: page,


Loading…
Cancel
Save