diff options
author | Lunny Xiao <xiaolunwen@gmail.com> | 2024-11-27 13:12:26 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-11-27 21:12:26 +0000 |
commit | f62f68cbdda07ae6933b4804bc757f35dc92d134 (patch) | |
tree | 6709319ec99caa6b22ed7d409f77ad17323f7808 /routers/api/v1 | |
parent | 5a50b271e71b5e8bb7bdef149e07dcd2b0db3e3a (diff) | |
download | gitea-f62f68cbdda07ae6933b4804bc757f35dc92d134.tar.gz gitea-f62f68cbdda07ae6933b4804bc757f35dc92d134.zip |
Move team related functions to service layer (#32537)
There are still some functions under `models` after last big refactor
about `models`. This change will move all team related functions to
service layer with no code change.
Diffstat (limited to 'routers/api/v1')
-rw-r--r-- | routers/api/v1/org/member.go | 4 | ||||
-rw-r--r-- | routers/api/v1/org/team.go | 13 | ||||
-rw-r--r-- | routers/api/v1/repo/teams.go | 3 |
3 files changed, 9 insertions, 11 deletions
diff --git a/routers/api/v1/org/member.go b/routers/api/v1/org/member.go index edcee1e207..294d33014d 100644 --- a/routers/api/v1/org/member.go +++ b/routers/api/v1/org/member.go @@ -7,7 +7,6 @@ import ( "net/http" "net/url" - "code.gitea.io/gitea/models" "code.gitea.io/gitea/models/organization" "code.gitea.io/gitea/modules/setting" api "code.gitea.io/gitea/modules/structs" @@ -15,6 +14,7 @@ import ( "code.gitea.io/gitea/routers/api/v1/utils" "code.gitea.io/gitea/services/context" "code.gitea.io/gitea/services/convert" + org_service "code.gitea.io/gitea/services/org" ) // listMembers list an organization's members @@ -322,7 +322,7 @@ func DeleteMember(ctx *context.APIContext) { if ctx.Written() { return } - if err := models.RemoveOrgUser(ctx, ctx.Org.Organization, member); err != nil { + if err := org_service.RemoveOrgUser(ctx, ctx.Org.Organization, member); err != nil { ctx.Error(http.StatusInternalServerError, "RemoveOrgUser", err) } ctx.Status(http.StatusNoContent) diff --git a/routers/api/v1/org/team.go b/routers/api/v1/org/team.go index c55837ff44..20226b4d6b 100644 --- a/routers/api/v1/org/team.go +++ b/routers/api/v1/org/team.go @@ -8,7 +8,6 @@ import ( "errors" "net/http" - "code.gitea.io/gitea/models" activities_model "code.gitea.io/gitea/models/activities" "code.gitea.io/gitea/models/organization" "code.gitea.io/gitea/models/perm" @@ -240,7 +239,7 @@ func CreateTeam(ctx *context.APIContext) { attachAdminTeamUnits(team) } - if err := models.NewTeam(ctx, team); err != nil { + if err := org_service.NewTeam(ctx, team); err != nil { if organization.IsErrTeamAlreadyExist(err) { ctx.Error(http.StatusUnprocessableEntity, "", err) } else { @@ -331,7 +330,7 @@ func EditTeam(ctx *context.APIContext) { attachAdminTeamUnits(team) } - if err := models.UpdateTeam(ctx, team, isAuthChanged, isIncludeAllChanged); err != nil { + if err := org_service.UpdateTeam(ctx, team, isAuthChanged, isIncludeAllChanged); err != nil { ctx.Error(http.StatusInternalServerError, "EditTeam", err) return } @@ -362,7 +361,7 @@ func DeleteTeam(ctx *context.APIContext) { // "404": // "$ref": "#/responses/notFound" - if err := models.DeleteTeam(ctx, ctx.Org.Team); err != nil { + if err := org_service.DeleteTeam(ctx, ctx.Org.Team); err != nil { ctx.Error(http.StatusInternalServerError, "DeleteTeam", err) return } @@ -496,7 +495,7 @@ func AddTeamMember(ctx *context.APIContext) { if ctx.Written() { return } - if err := models.AddTeamMember(ctx, ctx.Org.Team, u); err != nil { + if err := org_service.AddTeamMember(ctx, ctx.Org.Team, u); err != nil { if errors.Is(err, user_model.ErrBlockedUser) { ctx.Error(http.StatusForbidden, "AddTeamMember", err) } else { @@ -537,7 +536,7 @@ func RemoveTeamMember(ctx *context.APIContext) { return } - if err := models.RemoveTeamMember(ctx, ctx.Org.Team, u); err != nil { + if err := org_service.RemoveTeamMember(ctx, ctx.Org.Team, u); err != nil { ctx.Error(http.StatusInternalServerError, "RemoveTeamMember", err) return } @@ -700,7 +699,7 @@ func AddTeamRepository(ctx *context.APIContext) { ctx.Error(http.StatusForbidden, "", "Must have admin-level access to the repository") return } - if err := org_service.TeamAddRepository(ctx, ctx.Org.Team, repo); err != nil { + if err := repo_service.TeamAddRepository(ctx, ctx.Org.Team, repo); err != nil { ctx.Error(http.StatusInternalServerError, "TeamAddRepository", err) return } diff --git a/routers/api/v1/repo/teams.go b/routers/api/v1/repo/teams.go index ddd325482d..82ecaf3020 100644 --- a/routers/api/v1/repo/teams.go +++ b/routers/api/v1/repo/teams.go @@ -10,7 +10,6 @@ import ( "code.gitea.io/gitea/models/organization" "code.gitea.io/gitea/services/context" "code.gitea.io/gitea/services/convert" - org_service "code.gitea.io/gitea/services/org" repo_service "code.gitea.io/gitea/services/repository" ) @@ -205,7 +204,7 @@ func changeRepoTeam(ctx *context.APIContext, add bool) { ctx.Error(http.StatusUnprocessableEntity, "alreadyAdded", fmt.Errorf("team '%s' is already added to repo", team.Name)) return } - err = org_service.TeamAddRepository(ctx, team, ctx.Repo.Repository) + err = repo_service.TeamAddRepository(ctx, team, ctx.Repo.Repository) } else { if !repoHasTeam { ctx.Error(http.StatusUnprocessableEntity, "notAdded", fmt.Errorf("team '%s' was not added to repo", team.Name)) |