Skip to content

Commit

Permalink
api: Add an endpoint for GET '/user/teams'.
Browse files Browse the repository at this point in the history
A GET request to this endpoint lists all the teams that a user
belongs to.
  • Loading branch information
HarshitOnGitHub committed Jan 3, 2019
1 parent c0211a1 commit f530a7f
Show file tree
Hide file tree
Showing 7 changed files with 65 additions and 6 deletions.
4 changes: 2 additions & 2 deletions Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions routers/api/v1/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -463,6 +463,8 @@ func RegisterRoutes(m *macaron.Macaron) {
m.Get("/times", repo.ListMyTrackedTimes)

m.Get("/subscriptions", user.GetMyWatchedRepos)

m.Get("/teams", org.ListUserTeams)
}, reqToken())

// Repositories
Expand Down
35 changes: 35 additions & 0 deletions routers/api/v1/org/team.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,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
Expand Down
20 changes: 20 additions & 0 deletions templates/swagger/v1_json.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -5450,6 +5450,23 @@
}
}
},
"/user/teams": {
"get": {
"produces": [
"application/json"
],
"tags": [
"user"
],
"summary": "List all the teams a user belongs to",
"operationId": "userListTeams",
"responses": {
"200": {
"$ref": "#/responses/TeamList"
}
}
}
},
"/user/times": {
"get": {
"produces": [
Expand Down Expand Up @@ -7974,6 +7991,9 @@
"type": "string",
"x-go-name": "Name"
},
"organization": {
"$ref": "#/definitions/Organization"
},
"permission": {
"type": "string",
"enum": [
Expand Down
1 change: 1 addition & 0 deletions vendor/code.gitea.io/sdk/gitea/hook.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 4 additions & 3 deletions vendor/code.gitea.io/sdk/gitea/org_team.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion vendor/code.gitea.io/sdk/gitea/release.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit f530a7f

Please sign in to comment.