From 2bf8494332592b3c57f9a12a26b9abd356fb3f15 Mon Sep 17 00:00:00 2001 From: Unknwon <u@gogs.io> Date: Fri, 11 Mar 2016 15:33:12 -0500 Subject: #13 finish user and repository search Both are possible on explore and admin panel --- routers/api/v1/repo/repo.go | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) (limited to 'routers/api/v1/repo') diff --git a/routers/api/v1/repo/repo.go b/routers/api/v1/repo/repo.go index fc7a9cd442..e3d8368010 100644 --- a/routers/api/v1/repo/repo.go +++ b/routers/api/v1/repo/repo.go @@ -21,21 +21,21 @@ import ( // https://github.com/gogits/go-gogs-client/wiki/Repositories#search-repositories func Search(ctx *context.Context) { - opt := models.SearchOption{ - Keyword: path.Base(ctx.Query("q")), - Uid: com.StrTo(ctx.Query("uid")).MustInt64(), - Limit: com.StrTo(ctx.Query("limit")).MustInt(), + opts := &models.SearchRepoOptions{ + Keyword: path.Base(ctx.Query("q")), + OwnerID: com.StrTo(ctx.Query("uid")).MustInt64(), + PageSize: com.StrTo(ctx.Query("limit")).MustInt(), } - if opt.Limit == 0 { - opt.Limit = 10 + if opts.PageSize == 0 { + opts.PageSize = 10 } // Check visibility. - if ctx.IsSigned && opt.Uid > 0 { - if ctx.User.Id == opt.Uid { - opt.Private = true + if ctx.IsSigned && opts.OwnerID > 0 { + if ctx.User.Id == opts.OwnerID { + opts.Private = true } else { - u, err := models.GetUserByID(opt.Uid) + u, err := models.GetUserByID(opts.OwnerID) if err != nil { ctx.JSON(500, map[string]interface{}{ "ok": false, @@ -44,13 +44,13 @@ func Search(ctx *context.Context) { return } if u.IsOrganization() && u.IsOwnedBy(ctx.User.Id) { - opt.Private = true + opts.Private = true } // FIXME: how about collaborators? } } - repos, err := models.SearchRepositoryByName(opt) + repos, _, err := models.SearchRepositoryByName(opts) if err != nil { ctx.JSON(500, map[string]interface{}{ "ok": false, -- cgit v1.2.3