diff options
author | Harshit Bansal <harshitbansal2015@gmail.com> | 2019-01-17 06:09:50 +0530 |
---|---|---|
committer | techknowlogick <hello@techknowlogick.com> | 2019-01-16 19:39:50 -0500 |
commit | 5ac6da3c41f628f31b2805bfc422a3abb6b76d6b (patch) | |
tree | 590734fcb13c5250db894ffa19562f9a5e82b9af /routers/api/v1/org/team.go | |
parent | 734834a6761d446a6e0dc25a104e8272143f6045 (diff) | |
download | gitea-5ac6da3c41f628f31b2805bfc422a3abb6b76d6b.tar.gz gitea-5ac6da3c41f628f31b2805bfc422a3abb6b76d6b.zip |
api: Add missing GET teams endpoints (#5382)
* api: Add an endpoint to list a particular member of team.
* models: Rename `GetUserTeams()` to `GetUserOrgTeams()` in `org_team` model.
`GetUserTeams()` sounds a bit misnomer since it actually returns
the teams that user belongs to in a given organization rather than
all the teams across all the organization that the user has joined.
* models: Add `GetUserTeams()`.
Returns all the teams that a user belongs to.
* api: Add an endpoint for GET '/user/teams'.
A GET request to this endpoint lists all the teams that a user
belongs to.
Diffstat (limited to 'routers/api/v1/org/team.go')
-rw-r--r-- | routers/api/v1/org/team.go | 65 |
1 files changed, 65 insertions, 0 deletions
diff --git a/routers/api/v1/org/team.go b/routers/api/v1/org/team.go index a22d25eae3..a1916db00b 100644 --- a/routers/api/v1/org/team.go +++ b/routers/api/v1/org/team.go @@ -1,4 +1,5 @@ // Copyright 2016 The Gogs Authors. All rights reserved. +// Copyright 2019 The Gitea Authors. All rights reserved. // Use of this source code is governed by a MIT-style // license that can be found in the LICENSE file. @@ -42,6 +43,41 @@ func ListTeams(ctx *context.APIContext) { ctx.JSON(200, apiTeams) } +// ListUserTeams list all the teams a user belongs to +func ListUserTeams(ctx *context.APIContext) { + // swagger:operation GET /user/teams user userListTeams + // --- + // summary: List all the teams a user belongs to + // produces: + // - application/json + // responses: + // "200": + // "$ref": "#/responses/TeamList" + teams, err := models.GetUserTeams(ctx.User.ID) + if err != nil { + ctx.Error(500, "GetUserTeams", err) + return + } + + cache := make(map[int64]*api.Organization) + apiTeams := make([]*api.Team, len(teams)) + for i := range teams { + apiOrg, ok := cache[teams[i].OrgID] + if !ok { + org, err := models.GetUserByID(teams[i].OrgID) + if err != nil { + ctx.Error(500, "GetUserByID", err) + return + } + apiOrg = convert.ToOrganization(org) + cache[teams[i].OrgID] = apiOrg + } + apiTeams[i] = convert.ToTeam(teams[i]) + apiTeams[i].Organization = apiOrg + } + ctx.JSON(200, apiTeams) +} + // GetTeam api for get a team func GetTeam(ctx *context.APIContext) { // swagger:operation GET /teams/{id} organization orgGetTeam @@ -221,6 +257,35 @@ func GetTeamMembers(ctx *context.APIContext) { ctx.JSON(200, members) } +// GetTeamMember api for get a particular member of team +func GetTeamMember(ctx *context.APIContext) { + // swagger:operation GET /teams/{id}/members/{username} organization orgListTeamMember + // --- + // summary: List a particular member of team + // produces: + // - application/json + // parameters: + // - name: id + // in: path + // description: id of the team + // type: integer + // format: int64 + // required: true + // - name: username + // in: path + // description: username of the member to list + // type: string + // required: true + // responses: + // "200": + // "$ref": "#/responses/User" + u := user.GetUserByParams(ctx) + if ctx.Written() { + return + } + ctx.JSON(200, u.APIFormat()) +} + // AddTeamMember api for add a member to a team func AddTeamMember(ctx *context.APIContext) { // swagger:operation PUT /teams/{id}/members/{username} organization orgAddTeamMember |