Skip to content

Commit f530a7f

Browse files
api: Add an endpoint for GET '/user/teams'.
A GET request to this endpoint lists all the teams that a user belongs to.
1 parent c0211a1 commit f530a7f

File tree

7 files changed

+65
-6
lines changed

7 files changed

+65
-6
lines changed

Gopkg.lock

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

routers/api/v1/api.go

+2
Original file line numberDiff line numberDiff line change
@@ -463,6 +463,8 @@ func RegisterRoutes(m *macaron.Macaron) {
463463
m.Get("/times", repo.ListMyTrackedTimes)
464464

465465
m.Get("/subscriptions", user.GetMyWatchedRepos)
466+
467+
m.Get("/teams", org.ListUserTeams)
466468
}, reqToken())
467469

468470
// Repositories

routers/api/v1/org/team.go

+35
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,41 @@ func ListTeams(ctx *context.APIContext) {
4242
ctx.JSON(200, apiTeams)
4343
}
4444

45+
// ListUserTeams list all the teams a user belongs to
46+
func ListUserTeams(ctx *context.APIContext) {
47+
// swagger:operation GET /user/teams user userListTeams
48+
// ---
49+
// summary: List all the teams a user belongs to
50+
// produces:
51+
// - application/json
52+
// responses:
53+
// "200":
54+
// "$ref": "#/responses/TeamList"
55+
teams, err := models.GetUserTeams(ctx.User.ID)
56+
if err != nil {
57+
ctx.Error(500, "GetUserTeams", err)
58+
return
59+
}
60+
61+
cache := make(map[int64]*api.Organization)
62+
apiTeams := make([]*api.Team, len(teams))
63+
for i := range teams {
64+
apiOrg, ok := cache[teams[i].OrgID]
65+
if !ok {
66+
org, err := models.GetUserByID(teams[i].OrgID)
67+
if err != nil {
68+
ctx.Error(500, "GetUserByID", err)
69+
return
70+
}
71+
apiOrg = convert.ToOrganization(org)
72+
cache[teams[i].OrgID] = apiOrg
73+
}
74+
apiTeams[i] = convert.ToTeam(teams[i])
75+
apiTeams[i].Organization = apiOrg
76+
}
77+
ctx.JSON(200, apiTeams)
78+
}
79+
4580
// GetTeam api for get a team
4681
func GetTeam(ctx *context.APIContext) {
4782
// swagger:operation GET /teams/{id} organization orgGetTeam

templates/swagger/v1_json.tmpl

+20
Original file line numberDiff line numberDiff line change
@@ -5450,6 +5450,23 @@
54505450
}
54515451
}
54525452
},
5453+
"/user/teams": {
5454+
"get": {
5455+
"produces": [
5456+
"application/json"
5457+
],
5458+
"tags": [
5459+
"user"
5460+
],
5461+
"summary": "List all the teams a user belongs to",
5462+
"operationId": "userListTeams",
5463+
"responses": {
5464+
"200": {
5465+
"$ref": "#/responses/TeamList"
5466+
}
5467+
}
5468+
}
5469+
},
54535470
"/user/times": {
54545471
"get": {
54555472
"produces": [
@@ -7974,6 +7991,9 @@
79747991
"type": "string",
79757992
"x-go-name": "Name"
79767993
},
7994+
"organization": {
7995+
"$ref": "#/definitions/Organization"
7996+
},
79777997
"permission": {
79787998
"type": "string",
79797999
"enum": [

vendor/code.gitea.io/sdk/gitea/hook.go

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/code.gitea.io/sdk/gitea/org_team.go

+4-3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/code.gitea.io/sdk/gitea/release.go

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)