Browse Source

Merge branch 'fix-1591' of https://git.openi.org.cn/OpenI/aiforge into fix-1591

pull/1693/head
zhoupzh 3 years ago
parent
commit
5e17cb4f16
4 changed files with 26 additions and 17 deletions
  1. +6
    -3
      models/dataset_star.go
  2. +2
    -0
      modules/context/repo.go
  3. +17
    -13
      routers/repo/dataset.go
  4. +1
    -1
      routers/routes/routes.go

+ 6
- 3
models/dataset_star.go View File

@@ -51,9 +51,12 @@ func StarDataset(userID, datasetID int64, star bool) error {
return sess.Commit() return sess.Commit()
} }


func IsDatasetStaring(userID, datasetID int64) bool {

return isDatasetStaring(x, userID, datasetID)
func IsDatasetStaringByRepoId(userID, repoID int64) bool {
dataset, _ := GetDatasetByRepo(&Repository{ID: repoID})
if dataset == nil {
return false
}
return isDatasetStaring(x, userID, dataset.ID)
} }


func isDatasetStaring(e Engine, userID, datasetID int64) bool { func isDatasetStaring(e Engine, userID, datasetID int64) bool {


+ 2
- 0
modules/context/repo.go View File

@@ -475,6 +475,8 @@ func RepoAssignment() macaron.Handler {
if ctx.IsSigned { if ctx.IsSigned {
ctx.Data["IsWatchingRepo"] = models.IsWatching(ctx.User.ID, repo.ID) ctx.Data["IsWatchingRepo"] = models.IsWatching(ctx.User.ID, repo.ID)
ctx.Data["IsStaringRepo"] = models.IsStaring(ctx.User.ID, repo.ID) ctx.Data["IsStaringRepo"] = models.IsStaring(ctx.User.ID, repo.ID)

ctx.Data["IsStaringDataset"] = models.IsDatasetStaringByRepoId(ctx.User.ID, repo.ID)
} }


if repo.IsFork { if repo.IsFork {


+ 17
- 13
routers/repo/dataset.go View File

@@ -287,7 +287,7 @@ func DatasetAction(ctx *context.Context) {
func CurrentRepoDataset(ctx *context.Context) { func CurrentRepoDataset(ctx *context.Context) {
page := ctx.QueryInt("page") page := ctx.QueryInt("page")
cloudbrainType := ctx.QueryInt("type") cloudbrainType := ctx.QueryInt("type")
keyword := strings.Trim(ctx.Query("search"), " ")
keyword := strings.Trim(ctx.Query("q"), " ")


repo := ctx.Repo.Repository repo := ctx.Repo.Repository
var datasetIDs []int64 var datasetIDs []int64
@@ -325,15 +325,16 @@ func CurrentRepoDataset(ctx *context.Context) {
return return
} }
ctx.JSON(200, map[string]string{ ctx.JSON(200, map[string]string{
"data": string(data),
"count": strconv.FormatInt(count, 10),
"result_code": "0",
"data": string(data),
"count": strconv.FormatInt(count, 10),
}) })
} }


func MyDataset(ctx *context.Context) {
func MyDatasets(ctx *context.Context) {
page := ctx.QueryInt("page") page := ctx.QueryInt("page")
cloudbrainType := ctx.QueryInt("type") cloudbrainType := ctx.QueryInt("type")
keyword := strings.Trim(ctx.Query("search"), " ")
keyword := strings.Trim(ctx.Query("q"), " ")


uploaderID := ctx.User.ID uploaderID := ctx.User.ID
datasets, count, err := models.Attachments(&models.AttachmentsOptions{ datasets, count, err := models.Attachments(&models.AttachmentsOptions{
@@ -363,15 +364,16 @@ func MyDataset(ctx *context.Context) {
return return
} }
ctx.JSON(200, map[string]string{ ctx.JSON(200, map[string]string{
"data": string(data),
"count": strconv.FormatInt(count, 10),
"result_code": "0",
"data": string(data),
"count": strconv.FormatInt(count, 10),
}) })
} }


func PublicDataset(ctx *context.Context) { func PublicDataset(ctx *context.Context) {
page := ctx.QueryInt("page") page := ctx.QueryInt("page")
cloudbrainType := ctx.QueryInt("type") cloudbrainType := ctx.QueryInt("type")
keyword := strings.Trim(ctx.Query("search"), " ")
keyword := strings.Trim(ctx.Query("q"), " ")


datasets, count, err := models.Attachments(&models.AttachmentsOptions{ datasets, count, err := models.Attachments(&models.AttachmentsOptions{
ListOptions: models.ListOptions{ ListOptions: models.ListOptions{
@@ -400,15 +402,16 @@ func PublicDataset(ctx *context.Context) {
return return
} }
ctx.JSON(200, map[string]string{ ctx.JSON(200, map[string]string{
"data": string(data),
"count": strconv.FormatInt(count, 10),
"result_code": "0",
"data": string(data),
"count": strconv.FormatInt(count, 10),
}) })
} }


func MyFavoriteDataset(ctx *context.Context) { func MyFavoriteDataset(ctx *context.Context) {
page := ctx.QueryInt("page") page := ctx.QueryInt("page")
cloudbrainType := ctx.QueryInt("type") cloudbrainType := ctx.QueryInt("type")
keyword := strings.Trim(ctx.Query("search"), " ")
keyword := strings.Trim(ctx.Query("q"), " ")


var datasetIDs []int64 var datasetIDs []int64


@@ -448,7 +451,8 @@ func MyFavoriteDataset(ctx *context.Context) {
return return
} }
ctx.JSON(200, map[string]string{ ctx.JSON(200, map[string]string{
"data": string(data),
"count": strconv.FormatInt(count, 10),
"result_code": "0",
"data": string(data),
"count": strconv.FormatInt(count, 10),
}) })
} }

+ 1
- 1
routers/routes/routes.go View File

@@ -986,7 +986,7 @@ func RegisterRoutes(m *macaron.Macaron) {
m.Get("/edit/:id", reqRepoDatasetWriter, repo.EditDataset) m.Get("/edit/:id", reqRepoDatasetWriter, repo.EditDataset)
m.Post("/edit", reqRepoDatasetWriter, bindIgnErr(auth.EditDatasetForm{}), repo.EditDatasetPost) m.Post("/edit", reqRepoDatasetWriter, bindIgnErr(auth.EditDatasetForm{}), repo.EditDatasetPost)
m.Get("/current_repo", reqRepoDatasetReader, repo.CurrentRepoDataset) m.Get("/current_repo", reqRepoDatasetReader, repo.CurrentRepoDataset)
m.Get("/my_datasets", reqRepoDatasetReader, repo.MyDataset)
m.Get("/my_datasets", reqRepoDatasetReader, repo.MyDatasets)
m.Get("/public_datasets", reqRepoDatasetReader, repo.PublicDataset) m.Get("/public_datasets", reqRepoDatasetReader, repo.PublicDataset)
m.Get("/my_favorite", reqRepoDatasetReader, repo.MyFavoriteDataset) m.Get("/my_favorite", reqRepoDatasetReader, repo.MyFavoriteDataset)




Loading…
Cancel
Save