summaryrefslogtreecommitdiffstats
path: root/routers/api/v1/org/team.go
diff options
context:
space:
mode:
authorDavid Svantesson <davidsvantesson@gmail.com>2019-10-01 07:32:28 +0200
committerLunny Xiao <xiaolunwen@gmail.com>2019-10-01 13:32:28 +0800
commit36bcd4cd6b6d1131e3f812a825558fbfe5dcca20 (patch)
tree1606d302648ca6f2f6633d21aeb5d06a568b14d8 /routers/api/v1/org/team.go
parentd3bc3dd4d16aef053699d5bfc45039db060d373e (diff)
downloadgitea-36bcd4cd6b6d1131e3f812a825558fbfe5dcca20.tar.gz
gitea-36bcd4cd6b6d1131e3f812a825558fbfe5dcca20.zip
API endpoint for searching teams. (#8108)
* Api endpoint for searching teams. Signed-off-by: dasv <david.svantesson@qrtech.se> * Move API to /orgs/:org/teams/search Signed-off-by: David Svantesson <davidsvantesson@gmail.com> * Regenerate swagger Signed-off-by: David Svantesson <davidsvantesson@gmail.com> * Fix search is Get Signed-off-by: David Svantesson <davidsvantesson@gmail.com> * Add test for search team API. Signed-off-by: David Svantesson <davidsvantesson@gmail.com> * Update routers/api/v1/org/team.go grammar Co-Authored-By: Richard Mahn <richmahn@users.noreply.github.com> * Fix review comments Signed-off-by: David Svantesson <davidsvantesson@gmail.com> * Fix some issues in repo collaboration team search, after changes in this PR. Signed-off-by: David Svantesson <davidsvantesson@gmail.com> * Remove teamUser which is not used and replace with actual user id. Signed-off-by: David Svantesson <davidsvantesson@gmail.com> * Remove unused search variable UserIsAdmin. * Add paging to team search. * Re-genereate swagger Signed-off-by: David Svantesson <davidsvantesson@gmail.com> * Fix review comments Signed-off-by: David Svantesson <davidsvantesson@gmail.com> * fix * Regenerate swagger
Diffstat (limited to 'routers/api/v1/org/team.go')
-rw-r--r--routers/api/v1/org/team.go83
1 files changed, 83 insertions, 0 deletions
diff --git a/routers/api/v1/org/team.go b/routers/api/v1/org/team.go
index 7b8fd12fba..d01f051626 100644
--- a/routers/api/v1/org/team.go
+++ b/routers/api/v1/org/team.go
@@ -6,8 +6,11 @@
package org
import (
+ "strings"
+
"code.gitea.io/gitea/models"
"code.gitea.io/gitea/modules/context"
+ "code.gitea.io/gitea/modules/log"
api "code.gitea.io/gitea/modules/structs"
"code.gitea.io/gitea/routers/api/v1/convert"
"code.gitea.io/gitea/routers/api/v1/user"
@@ -504,3 +507,83 @@ func RemoveTeamRepository(ctx *context.APIContext) {
}
ctx.Status(204)
}
+
+// SearchTeam api for searching teams
+func SearchTeam(ctx *context.APIContext) {
+ // swagger:operation GET /orgs/{org}/teams/search organization teamSearch
+ // ---
+ // summary: Search for teams within an organization
+ // produces:
+ // - application/json
+ // parameters:
+ // - name: org
+ // in: path
+ // description: name of the organization
+ // type: string
+ // required: true
+ // - name: q
+ // in: query
+ // description: keywords to search
+ // type: string
+ // - name: include_desc
+ // in: query
+ // description: include search within team description (defaults to true)
+ // type: boolean
+ // - name: limit
+ // in: query
+ // description: limit size of results
+ // type: integer
+ // - name: page
+ // in: query
+ // description: page number of results to return (1-based)
+ // type: integer
+ // responses:
+ // "200":
+ // description: "SearchResults of a successful search"
+ // schema:
+ // type: object
+ // properties:
+ // ok:
+ // type: boolean
+ // data:
+ // type: array
+ // items:
+ // "$ref": "#/definitions/Team"
+ opts := &models.SearchTeamOptions{
+ UserID: ctx.User.ID,
+ Keyword: strings.TrimSpace(ctx.Query("q")),
+ OrgID: ctx.Org.Organization.ID,
+ IncludeDesc: (ctx.Query("include_desc") == "" || ctx.QueryBool("include_desc")),
+ PageSize: ctx.QueryInt("limit"),
+ Page: ctx.QueryInt("page"),
+ }
+
+ teams, _, err := models.SearchTeam(opts)
+ if err != nil {
+ log.Error("SearchTeam failed: %v", err)
+ ctx.JSON(500, map[string]interface{}{
+ "ok": false,
+ "error": "SearchTeam internal failure",
+ })
+ return
+ }
+
+ apiTeams := make([]*api.Team, len(teams))
+ for i := range teams {
+ if err := teams[i].GetUnits(); err != nil {
+ log.Error("Team GetUnits failed: %v", err)
+ ctx.JSON(500, map[string]interface{}{
+ "ok": false,
+ "error": "SearchTeam failed to get units",
+ })
+ return
+ }
+ apiTeams[i] = convert.ToTeam(teams[i])
+ }
+
+ ctx.JSON(200, map[string]interface{}{
+ "ok": true,
+ "data": apiTeams,
+ })
+
+}