mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2025-05-31 11:52:10 +00:00
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.
This commit is contained in:
parent
734834a676
commit
5ac6da3c41
10 changed files with 160 additions and 12 deletions
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue