aboutsummaryrefslogtreecommitdiff
path: root/routers/api/v1/user.go
diff options
context:
space:
mode:
authorUnknwon <u@gogs.io>2015-12-04 17:16:42 -0500
committerUnknwon <u@gogs.io>2015-12-04 17:16:42 -0500
commit56dd430a10bf5281caf648344e4660fbdc5d4dee (patch)
tree9493b1a9f77321525d62ce1ccefc4dd792391832 /routers/api/v1/user.go
parente0bae9547af03e5e7c0201faaa9568d6a1cc9e1f (diff)
refactor API routes and some work for #976
Diffstat (limited to 'routers/api/v1/user.go')
-rw-r--r--routers/api/v1/user.go82
1 files changed, 0 insertions, 82 deletions
diff --git a/routers/api/v1/user.go b/routers/api/v1/user.go
deleted file mode 100644
index 36a1872b..00000000
--- a/routers/api/v1/user.go
+++ /dev/null
@@ -1,82 +0,0 @@
-// Copyright 2014 The Gogs Authors. All rights reserved.
-// Use of this source code is governed by a MIT-style
-// license that can be found in the LICENSE file.
-
-package v1
-
-import (
- "github.com/Unknwon/com"
-
- api "github.com/gogits/go-gogs-client"
-
- "github.com/gogits/gogs/models"
- "github.com/gogits/gogs/modules/middleware"
-)
-
-// ToApiUser converts user to API format.
-func ToApiUser(u *models.User) *api.User {
- return &api.User{
- ID: u.Id,
- UserName: u.Name,
- FullName: u.FullName,
- Email: u.Email,
- AvatarUrl: u.AvatarLink(),
- }
-}
-
-// https://github.com/gogits/go-gogs-client/wiki/Users#search-users
-func SearchUsers(ctx *middleware.Context) {
- opt := models.SearchOption{
- Keyword: ctx.Query("q"),
- Limit: com.StrTo(ctx.Query("limit")).MustInt(),
- }
- if opt.Limit == 0 {
- opt.Limit = 10
- }
-
- us, err := models.SearchUserByName(opt)
- if err != nil {
- ctx.JSON(500, map[string]interface{}{
- "ok": false,
- "error": err.Error(),
- })
- return
- }
-
- results := make([]*api.User, len(us))
- for i := range us {
- results[i] = &api.User{
- ID: us[i].Id,
- UserName: us[i].Name,
- AvatarUrl: us[i].AvatarLink(),
- FullName: us[i].FullName,
- }
- if ctx.IsSigned {
- results[i].Email = us[i].Email
- }
- }
-
- ctx.JSON(200, map[string]interface{}{
- "ok": true,
- "data": results,
- })
-}
-
-// https://github.com/gogits/go-gogs-client/wiki/Users#get-a-single-user
-func GetUserInfo(ctx *middleware.Context) {
- u, err := models.GetUserByName(ctx.Params(":username"))
- if err != nil {
- if models.IsErrUserNotExist(err) {
- ctx.Error(404)
- } else {
- ctx.APIError(500, "GetUserByName", err)
- }
- return
- }
-
- // Hide user e-mail when API caller isn't signed in.
- if !ctx.IsSigned {
- u.Email = ""
- }
- ctx.JSON(200, &api.User{u.Id, u.Name, u.FullName, u.Email, u.AvatarLink()})
-}