summaryrefslogtreecommitdiffstats
path: root/routers/api
diff options
context:
space:
mode:
authorUnknwon <u@gogs.io>2016-03-11 15:33:12 -0500
committerUnknwon <u@gogs.io>2016-03-11 15:33:12 -0500
commit2bf8494332592b3c57f9a12a26b9abd356fb3f15 (patch)
treee46c61ba30018ebbafcda6b97b36d3ffece3cfb0 /routers/api
parentdf2bdf7ea36ad0729e0326ca799d8896d7f96946 (diff)
downloadgitea-2bf8494332592b3c57f9a12a26b9abd356fb3f15.tar.gz
gitea-2bf8494332592b3c57f9a12a26b9abd356fb3f15.zip
#13 finish user and repository search
Both are possible on explore and admin panel
Diffstat (limited to 'routers/api')
-rw-r--r--routers/api/v1/admin/orgs.go2
-rw-r--r--routers/api/v1/repo/repo.go24
-rw-r--r--routers/api/v1/user/user.go27
3 files changed, 27 insertions, 26 deletions
diff --git a/routers/api/v1/admin/orgs.go b/routers/api/v1/admin/orgs.go
index fbfcd400ae..f212c4f517 100644
--- a/routers/api/v1/admin/orgs.go
+++ b/routers/api/v1/admin/orgs.go
@@ -27,7 +27,7 @@ func CreateOrg(ctx *context.Context, form api.CreateOrgOption) {
Website: form.Website,
Location: form.Location,
IsActive: true,
- Type: models.ORGANIZATION,
+ Type: models.USER_TYPE_ORGANIZATION,
}
if err := models.CreateOrganization(org, u); err != nil {
if models.IsErrUserAlreadyExist(err) ||
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,
diff --git a/routers/api/v1/user/user.go b/routers/api/v1/user/user.go
index d08fd20241..71056894a5 100644
--- a/routers/api/v1/user/user.go
+++ b/routers/api/v1/user/user.go
@@ -15,15 +15,16 @@ import (
// https://github.com/gogits/go-gogs-client/wiki/Users#search-users
func Search(ctx *context.Context) {
- opt := models.SearchOption{
- Keyword: ctx.Query("q"),
- Limit: com.StrTo(ctx.Query("limit")).MustInt(),
+ opts := &models.SearchUserOptions{
+ Keyword: ctx.Query("q"),
+ Type: models.USER_TYPE_INDIVIDUAL,
+ PageSize: com.StrTo(ctx.Query("limit")).MustInt(),
}
- if opt.Limit == 0 {
- opt.Limit = 10
+ if opts.PageSize == 0 {
+ opts.PageSize = 10
}
- us, err := models.SearchUserByName(opt)
+ users, _, err := models.SearchUserByName(opts)
if err != nil {
ctx.JSON(500, map[string]interface{}{
"ok": false,
@@ -32,16 +33,16 @@ func Search(ctx *context.Context) {
return
}
- results := make([]*api.User, len(us))
- for i := range us {
+ results := make([]*api.User, len(users))
+ for i := range users {
results[i] = &api.User{
- ID: us[i].Id,
- UserName: us[i].Name,
- AvatarUrl: us[i].AvatarLink(),
- FullName: us[i].FullName,
+ ID: users[i].Id,
+ UserName: users[i].Name,
+ AvatarUrl: users[i].AvatarLink(),
+ FullName: users[i].FullName,
}
if ctx.IsSigned {
- results[i].Email = us[i].Email
+ results[i].Email = users[i].Email
}
}