aboutsummaryrefslogtreecommitdiffstats
path: root/routers/api/v1/org/team.go
diff options
context:
space:
mode:
Diffstat (limited to 'routers/api/v1/org/team.go')
-rw-r--r--routers/api/v1/org/team.go41
1 files changed, 25 insertions, 16 deletions
diff --git a/routers/api/v1/org/team.go b/routers/api/v1/org/team.go
index 7998bb249f..a84763d6f6 100644
--- a/routers/api/v1/org/team.go
+++ b/routers/api/v1/org/team.go
@@ -6,7 +6,6 @@
package org
import (
- "fmt"
"net/http"
"code.gitea.io/gitea/models"
@@ -44,23 +43,27 @@ func ListTeams(ctx *context.APIContext) {
// "200":
// "$ref": "#/responses/TeamList"
- org := ctx.Org.Organization
- if err := org.GetTeams(&models.SearchTeamOptions{
+ teams, count, err := models.SearchTeam(&models.SearchTeamOptions{
ListOptions: utils.GetListOptions(ctx),
- }); err != nil {
- ctx.Error(http.StatusInternalServerError, "GetTeams", err)
+ OrgID: ctx.Org.Organization.ID,
+ })
+
+ if err != nil {
+ ctx.Error(http.StatusInternalServerError, "LoadTeams", err)
return
}
- apiTeams := make([]*api.Team, len(org.Teams))
- for i := range org.Teams {
- if err := org.Teams[i].GetUnits(); err != nil {
+ apiTeams := make([]*api.Team, len(teams))
+ for i := range teams {
+ if err := teams[i].GetUnits(); err != nil {
ctx.Error(http.StatusInternalServerError, "GetUnits", err)
return
}
- apiTeams[i] = convert.ToTeam(org.Teams[i])
+ apiTeams[i] = convert.ToTeam(teams[i])
}
+
+ ctx.SetTotalCountHeader(count)
ctx.JSON(http.StatusOK, apiTeams)
}
@@ -84,7 +87,10 @@ func ListUserTeams(ctx *context.APIContext) {
// "200":
// "$ref": "#/responses/TeamList"
- teams, err := models.GetUserTeams(ctx.User.ID, utils.GetListOptions(ctx))
+ teams, count, err := models.SearchTeam(&models.SearchTeamOptions{
+ ListOptions: utils.GetListOptions(ctx),
+ UserID: ctx.User.ID,
+ })
if err != nil {
ctx.Error(http.StatusInternalServerError, "GetUserTeams", err)
return
@@ -106,6 +112,8 @@ func ListUserTeams(ctx *context.APIContext) {
apiTeams[i] = convert.ToTeam(teams[i])
apiTeams[i].Organization = apiOrg
}
+
+ ctx.SetTotalCountHeader(count)
ctx.JSON(http.StatusOK, apiTeams)
}
@@ -327,17 +335,19 @@ func GetTeamMembers(ctx *context.APIContext) {
ctx.NotFound()
return
}
- team := ctx.Org.Team
- if err := team.GetMembers(&models.SearchMembersOptions{
+
+ if err := ctx.Org.Team.GetMembers(&models.SearchMembersOptions{
ListOptions: utils.GetListOptions(ctx),
}); err != nil {
ctx.Error(http.StatusInternalServerError, "GetTeamMembers", err)
return
}
- members := make([]*api.User, len(team.Members))
- for i, member := range team.Members {
+ members := make([]*api.User, len(ctx.Org.Team.Members))
+ for i, member := range ctx.Org.Team.Members {
members[i] = convert.ToUser(member, ctx.User)
}
+
+ ctx.SetTotalCountHeader(int64(ctx.Org.Team.NumMembers))
ctx.JSON(http.StatusOK, members)
}
@@ -687,8 +697,7 @@ func SearchTeam(ctx *context.APIContext) {
}
ctx.SetLinkHeader(int(maxResults), listOptions.PageSize)
- ctx.Header().Set("X-Total-Count", fmt.Sprintf("%d", maxResults))
- ctx.Header().Set("Access-Control-Expose-Headers", "X-Total-Count, Link")
+ ctx.SetTotalCountHeader(maxResults)
ctx.JSON(http.StatusOK, map[string]interface{}{
"ok": true,
"data": apiTeams,