aboutsummaryrefslogtreecommitdiffstats
path: root/routers/api
diff options
context:
space:
mode:
Diffstat (limited to 'routers/api')
-rw-r--r--routers/api/packages/nuget/auth.go8
-rw-r--r--routers/api/v1/admin/adopt.go4
-rw-r--r--routers/api/v1/notify/notifications.go18
-rw-r--r--routers/api/v1/notify/repo.go26
-rw-r--r--routers/api/v1/notify/threads.go10
-rw-r--r--routers/api/v1/notify/user.go14
-rw-r--r--routers/api/v1/org/team.go5
-rw-r--r--routers/api/v1/repo/collaborators.go3
-rw-r--r--routers/api/v1/repo/migrate.go2
-rw-r--r--routers/api/v1/repo/pull.go3
-rw-r--r--routers/api/v1/repo/release.go35
-rw-r--r--routers/api/v1/repo/release_attachment.go9
-rw-r--r--routers/api/v1/repo/release_tags.go9
-rw-r--r--routers/api/v1/repo/repo.go3
-rw-r--r--routers/api/v1/repo/tag.go5
-rw-r--r--routers/api/v1/repo/teams.go3
-rw-r--r--routers/api/v1/repo/wiki.go8
-rw-r--r--routers/api/v1/swagger/user.go4
-rw-r--r--routers/api/v1/user/app.go37
-rw-r--r--routers/api/v1/user/user.go4
20 files changed, 107 insertions, 103 deletions
diff --git a/routers/api/packages/nuget/auth.go b/routers/api/packages/nuget/auth.go
index 26a5b90189..1dad452648 100644
--- a/routers/api/packages/nuget/auth.go
+++ b/routers/api/packages/nuget/auth.go
@@ -7,7 +7,7 @@ package nuget
import (
"net/http"
- "code.gitea.io/gitea/models"
+ auth_model "code.gitea.io/gitea/models/auth"
user_model "code.gitea.io/gitea/models/user"
"code.gitea.io/gitea/modules/log"
"code.gitea.io/gitea/modules/timeutil"
@@ -22,9 +22,9 @@ func (a *Auth) Name() string {
// https://docs.microsoft.com/en-us/nuget/api/package-publish-resource#request-parameters
func (a *Auth) Verify(req *http.Request, w http.ResponseWriter, store auth.DataStore, sess auth.SessionStore) *user_model.User {
- token, err := models.GetAccessTokenBySHA(req.Header.Get("X-NuGet-ApiKey"))
+ token, err := auth_model.GetAccessTokenBySHA(req.Header.Get("X-NuGet-ApiKey"))
if err != nil {
- if !(models.IsErrAccessTokenNotExist(err) || models.IsErrAccessTokenEmpty(err)) {
+ if !(auth_model.IsErrAccessTokenNotExist(err) || auth_model.IsErrAccessTokenEmpty(err)) {
log.Error("GetAccessTokenBySHA: %v", err)
}
return nil
@@ -37,7 +37,7 @@ func (a *Auth) Verify(req *http.Request, w http.ResponseWriter, store auth.DataS
}
token.UpdatedUnix = timeutil.TimeStampNow()
- if err := models.UpdateAccessToken(token); err != nil {
+ if err := auth_model.UpdateAccessToken(token); err != nil {
log.Error("UpdateAccessToken: %v", err)
}
diff --git a/routers/api/v1/admin/adopt.go b/routers/api/v1/admin/adopt.go
index 8f11ab67f0..48222f89eb 100644
--- a/routers/api/v1/admin/adopt.go
+++ b/routers/api/v1/admin/adopt.go
@@ -7,10 +7,10 @@ package admin
import (
"net/http"
- "code.gitea.io/gitea/models"
repo_model "code.gitea.io/gitea/models/repo"
user_model "code.gitea.io/gitea/models/user"
"code.gitea.io/gitea/modules/context"
+ repo_module "code.gitea.io/gitea/modules/repository"
"code.gitea.io/gitea/modules/util"
"code.gitea.io/gitea/routers/api/v1/utils"
repo_service "code.gitea.io/gitea/services/repository"
@@ -110,7 +110,7 @@ func AdoptRepository(ctx *context.APIContext) {
ctx.NotFound()
return
}
- if _, err := repo_service.AdoptRepository(ctx.Doer, ctxUser, models.CreateRepoOptions{
+ if _, err := repo_service.AdoptRepository(ctx.Doer, ctxUser, repo_module.CreateRepoOptions{
Name: repoName,
IsPrivate: true,
}); err != nil {
diff --git a/routers/api/v1/notify/notifications.go b/routers/api/v1/notify/notifications.go
index 44cb4ae769..9948f90a12 100644
--- a/routers/api/v1/notify/notifications.go
+++ b/routers/api/v1/notify/notifications.go
@@ -8,7 +8,7 @@ import (
"net/http"
"strings"
- "code.gitea.io/gitea/models"
+ activities_model "code.gitea.io/gitea/models/activities"
"code.gitea.io/gitea/modules/context"
api "code.gitea.io/gitea/modules/structs"
"code.gitea.io/gitea/routers/api/v1/utils"
@@ -22,16 +22,16 @@ func NewAvailable(ctx *context.APIContext) {
// responses:
// "200":
// "$ref": "#/responses/NotificationCount"
- ctx.JSON(http.StatusOK, api.NotificationCount{New: models.CountUnread(ctx, ctx.Doer.ID)})
+ ctx.JSON(http.StatusOK, api.NotificationCount{New: activities_model.CountUnread(ctx, ctx.Doer.ID)})
}
-func getFindNotificationOptions(ctx *context.APIContext) *models.FindNotificationOptions {
+func getFindNotificationOptions(ctx *context.APIContext) *activities_model.FindNotificationOptions {
before, since, err := context.GetQueryBeforeSince(ctx.Context)
if err != nil {
ctx.Error(http.StatusUnprocessableEntity, "GetQueryBeforeSince", err)
return nil
}
- opts := &models.FindNotificationOptions{
+ opts := &activities_model.FindNotificationOptions{
ListOptions: utils.GetListOptions(ctx),
UserID: ctx.Doer.ID,
UpdatedBeforeUnix: before,
@@ -50,17 +50,17 @@ func getFindNotificationOptions(ctx *context.APIContext) *models.FindNotificatio
return opts
}
-func subjectToSource(value []string) (result []models.NotificationSource) {
+func subjectToSource(value []string) (result []activities_model.NotificationSource) {
for _, v := range value {
switch strings.ToLower(v) {
case "issue":
- result = append(result, models.NotificationSourceIssue)
+ result = append(result, activities_model.NotificationSourceIssue)
case "pull":
- result = append(result, models.NotificationSourcePullRequest)
+ result = append(result, activities_model.NotificationSourcePullRequest)
case "commit":
- result = append(result, models.NotificationSourceCommit)
+ result = append(result, activities_model.NotificationSourceCommit)
case "repository":
- result = append(result, models.NotificationSourceRepository)
+ result = append(result, activities_model.NotificationSourceRepository)
}
}
return result
diff --git a/routers/api/v1/notify/repo.go b/routers/api/v1/notify/repo.go
index 4e9dd806de..f8e1fb0865 100644
--- a/routers/api/v1/notify/repo.go
+++ b/routers/api/v1/notify/repo.go
@@ -9,31 +9,31 @@ import (
"strings"
"time"
- "code.gitea.io/gitea/models"
+ activities_model "code.gitea.io/gitea/models/activities"
"code.gitea.io/gitea/modules/context"
"code.gitea.io/gitea/modules/convert"
"code.gitea.io/gitea/modules/log"
"code.gitea.io/gitea/modules/structs"
)
-func statusStringToNotificationStatus(status string) models.NotificationStatus {
+func statusStringToNotificationStatus(status string) activities_model.NotificationStatus {
switch strings.ToLower(strings.TrimSpace(status)) {
case "unread":
- return models.NotificationStatusUnread
+ return activities_model.NotificationStatusUnread
case "read":
- return models.NotificationStatusRead
+ return activities_model.NotificationStatusRead
case "pinned":
- return models.NotificationStatusPinned
+ return activities_model.NotificationStatusPinned
default:
return 0
}
}
-func statusStringsToNotificationStatuses(statuses, defaultStatuses []string) []models.NotificationStatus {
+func statusStringsToNotificationStatuses(statuses, defaultStatuses []string) []activities_model.NotificationStatus {
if len(statuses) == 0 {
statuses = defaultStatuses
}
- results := make([]models.NotificationStatus, 0, len(statuses))
+ results := make([]activities_model.NotificationStatus, 0, len(statuses))
for _, status := range statuses {
notificationStatus := statusStringToNotificationStatus(status)
if notificationStatus > 0 {
@@ -109,13 +109,13 @@ func ListRepoNotifications(ctx *context.APIContext) {
}
opts.RepoID = ctx.Repo.Repository.ID
- totalCount, err := models.CountNotifications(opts)
+ totalCount, err := activities_model.CountNotifications(opts)
if err != nil {
ctx.InternalServerError(err)
return
}
- nl, err := models.GetNotifications(ctx, opts)
+ nl, err := activities_model.GetNotifications(ctx, opts)
if err != nil {
ctx.InternalServerError(err)
return
@@ -192,7 +192,7 @@ func ReadRepoNotifications(ctx *context.APIContext) {
}
}
- opts := &models.FindNotificationOptions{
+ opts := &activities_model.FindNotificationOptions{
UserID: ctx.Doer.ID,
RepoID: ctx.Repo.Repository.ID,
UpdatedBeforeUnix: lastRead,
@@ -203,7 +203,7 @@ func ReadRepoNotifications(ctx *context.APIContext) {
opts.Status = statusStringsToNotificationStatuses(statuses, []string{"unread"})
log.Error("%v", opts.Status)
}
- nl, err := models.GetNotifications(ctx, opts)
+ nl, err := activities_model.GetNotifications(ctx, opts)
if err != nil {
ctx.InternalServerError(err)
return
@@ -211,13 +211,13 @@ func ReadRepoNotifications(ctx *context.APIContext) {
targetStatus := statusStringToNotificationStatus(ctx.FormString("to-status"))
if targetStatus == 0 {
- targetStatus = models.NotificationStatusRead
+ targetStatus = activities_model.NotificationStatusRead
}
changed := make([]*structs.NotificationThread, 0, len(nl))
for _, n := range nl {
- notif, err := models.SetNotificationStatus(n.ID, ctx.Doer, targetStatus)
+ notif, err := activities_model.SetNotificationStatus(n.ID, ctx.Doer, targetStatus)
if err != nil {
ctx.InternalServerError(err)
return
diff --git a/routers/api/v1/notify/threads.go b/routers/api/v1/notify/threads.go
index 7d8d34504f..44a1d30a55 100644
--- a/routers/api/v1/notify/threads.go
+++ b/routers/api/v1/notify/threads.go
@@ -8,7 +8,7 @@ import (
"fmt"
"net/http"
- "code.gitea.io/gitea/models"
+ activities_model "code.gitea.io/gitea/models/activities"
"code.gitea.io/gitea/models/db"
issues_model "code.gitea.io/gitea/models/issues"
"code.gitea.io/gitea/modules/context"
@@ -86,10 +86,10 @@ func ReadThread(ctx *context.APIContext) {
targetStatus := statusStringToNotificationStatus(ctx.FormString("to-status"))
if targetStatus == 0 {
- targetStatus = models.NotificationStatusRead
+ targetStatus = activities_model.NotificationStatusRead
}
- notif, err := models.SetNotificationStatus(n.ID, ctx.Doer, targetStatus)
+ notif, err := activities_model.SetNotificationStatus(n.ID, ctx.Doer, targetStatus)
if err != nil {
ctx.InternalServerError(err)
return
@@ -101,8 +101,8 @@ func ReadThread(ctx *context.APIContext) {
ctx.JSON(http.StatusResetContent, convert.ToNotificationThread(notif))
}
-func getThread(ctx *context.APIContext) *models.Notification {
- n, err := models.GetNotificationByID(ctx.ParamsInt64(":id"))
+func getThread(ctx *context.APIContext) *activities_model.Notification {
+ n, err := activities_model.GetNotificationByID(ctx.ParamsInt64(":id"))
if err != nil {
if db.IsErrNotExist(err) {
ctx.Error(http.StatusNotFound, "GetNotificationByID", err)
diff --git a/routers/api/v1/notify/user.go b/routers/api/v1/notify/user.go
index b923307783..1b6706e16f 100644
--- a/routers/api/v1/notify/user.go
+++ b/routers/api/v1/notify/user.go
@@ -8,7 +8,7 @@ import (
"net/http"
"time"
- "code.gitea.io/gitea/models"
+ activities_model "code.gitea.io/gitea/models/activities"
"code.gitea.io/gitea/modules/context"
"code.gitea.io/gitea/modules/convert"
"code.gitea.io/gitea/modules/structs"
@@ -69,13 +69,13 @@ func ListNotifications(ctx *context.APIContext) {
return
}
- totalCount, err := models.CountNotifications(opts)
+ totalCount, err := activities_model.CountNotifications(opts)
if err != nil {
ctx.InternalServerError(err)
return
}
- nl, err := models.GetNotifications(ctx, opts)
+ nl, err := activities_model.GetNotifications(ctx, opts)
if err != nil {
ctx.InternalServerError(err)
return
@@ -140,7 +140,7 @@ func ReadNotifications(ctx *context.APIContext) {
lastRead = tmpLastRead.Unix()
}
}
- opts := &models.FindNotificationOptions{
+ opts := &activities_model.FindNotificationOptions{
UserID: ctx.Doer.ID,
UpdatedBeforeUnix: lastRead,
}
@@ -148,7 +148,7 @@ func ReadNotifications(ctx *context.APIContext) {
statuses := ctx.FormStrings("status-types")
opts.Status = statusStringsToNotificationStatuses(statuses, []string{"unread"})
}
- nl, err := models.GetNotifications(ctx, opts)
+ nl, err := activities_model.GetNotifications(ctx, opts)
if err != nil {
ctx.InternalServerError(err)
return
@@ -156,13 +156,13 @@ func ReadNotifications(ctx *context.APIContext) {
targetStatus := statusStringToNotificationStatus(ctx.FormString("to-status"))
if targetStatus == 0 {
- targetStatus = models.NotificationStatusRead
+ targetStatus = activities_model.NotificationStatusRead
}
changed := make([]*structs.NotificationThread, 0, len(nl))
for _, n := range nl {
- notif, err := models.SetNotificationStatus(n.ID, ctx.Doer, targetStatus)
+ notif, err := activities_model.SetNotificationStatus(n.ID, ctx.Doer, targetStatus)
if err != nil {
ctx.InternalServerError(err)
return
diff --git a/routers/api/v1/org/team.go b/routers/api/v1/org/team.go
index db37bac57e..c891d0e122 100644
--- a/routers/api/v1/org/team.go
+++ b/routers/api/v1/org/team.go
@@ -22,6 +22,7 @@ import (
"code.gitea.io/gitea/modules/web"
"code.gitea.io/gitea/routers/api/v1/user"
"code.gitea.io/gitea/routers/api/v1/utils"
+ org_service "code.gitea.io/gitea/services/org"
)
// ListTeams list all the teams of an organization
@@ -656,8 +657,8 @@ func AddTeamRepository(ctx *context.APIContext) {
ctx.Error(http.StatusForbidden, "", "Must have admin-level access to the repository")
return
}
- if err := models.AddRepository(ctx.Org.Team, repo); err != nil {
- ctx.Error(http.StatusInternalServerError, "AddRepository", err)
+ if err := org_service.TeamAddRepository(ctx.Org.Team, repo); err != nil {
+ ctx.Error(http.StatusInternalServerError, "TeamAddRepository", err)
return
}
ctx.Status(http.StatusNoContent)
diff --git a/routers/api/v1/repo/collaborators.go b/routers/api/v1/repo/collaborators.go
index aa425e5828..0e6236216c 100644
--- a/routers/api/v1/repo/collaborators.go
+++ b/routers/api/v1/repo/collaborators.go
@@ -16,6 +16,7 @@ import (
user_model "code.gitea.io/gitea/models/user"
"code.gitea.io/gitea/modules/context"
"code.gitea.io/gitea/modules/convert"
+ repo_module "code.gitea.io/gitea/modules/repository"
api "code.gitea.io/gitea/modules/structs"
"code.gitea.io/gitea/modules/web"
"code.gitea.io/gitea/routers/api/v1/utils"
@@ -174,7 +175,7 @@ func AddCollaborator(ctx *context.APIContext) {
return
}
- if err := models.AddCollaborator(ctx.Repo.Repository, collaborator); err != nil {
+ if err := repo_module.AddCollaborator(ctx.Repo.Repository, collaborator); err != nil {
ctx.Error(http.StatusInternalServerError, "AddCollaborator", err)
return
}
diff --git a/routers/api/v1/repo/migrate.go b/routers/api/v1/repo/migrate.go
index f868c53951..ed371d787c 100644
--- a/routers/api/v1/repo/migrate.go
+++ b/routers/api/v1/repo/migrate.go
@@ -170,7 +170,7 @@ func Migrate(ctx *context.APIContext) {
opts.Releases = false
}
- repo, err := repo_module.CreateRepository(ctx.Doer, repoOwner, models.CreateRepoOptions{
+ repo, err := repo_module.CreateRepository(ctx.Doer, repoOwner, repo_module.CreateRepoOptions{
Name: opts.RepoName,
Description: opts.Description,
OriginalURL: form.CloneAddr,
diff --git a/routers/api/v1/repo/pull.go b/routers/api/v1/repo/pull.go
index 50d2c9484f..dda05203df 100644
--- a/routers/api/v1/repo/pull.go
+++ b/routers/api/v1/repo/pull.go
@@ -14,6 +14,7 @@ import (
"time"
"code.gitea.io/gitea/models"
+ activities_model "code.gitea.io/gitea/models/activities"
issues_model "code.gitea.io/gitea/models/issues"
access_model "code.gitea.io/gitea/models/perm/access"
pull_model "code.gitea.io/gitea/models/pull"
@@ -753,7 +754,7 @@ func MergePullRequest(ctx *context.APIContext) {
if ctx.IsSigned {
// Update issue-user.
- if err = models.SetIssueReadBy(ctx, pr.Issue.ID, ctx.Doer.ID); err != nil {
+ if err = activities_model.SetIssueReadBy(ctx, pr.Issue.ID, ctx.Doer.ID); err != nil {
ctx.Error(http.StatusInternalServerError, "ReadBy", err)
return
}
diff --git a/routers/api/v1/repo/release.go b/routers/api/v1/repo/release.go
index 80009f78e9..acc9696e1b 100644
--- a/routers/api/v1/repo/release.go
+++ b/routers/api/v1/repo/release.go
@@ -9,6 +9,7 @@ import (
"code.gitea.io/gitea/models"
"code.gitea.io/gitea/models/perm"
+ repo_model "code.gitea.io/gitea/models/repo"
"code.gitea.io/gitea/models/unit"
"code.gitea.io/gitea/modules/context"
"code.gitea.io/gitea/modules/convert"
@@ -49,12 +50,12 @@ func GetRelease(ctx *context.APIContext) {
// "$ref": "#/responses/notFound"
id := ctx.ParamsInt64(":id")
- release, err := models.GetReleaseByID(ctx, id)
- if err != nil && !models.IsErrReleaseNotExist(err) {
+ release, err := repo_model.GetReleaseByID(ctx, id)
+ if err != nil && !repo_model.IsErrReleaseNotExist(err) {
ctx.Error(http.StatusInternalServerError, "GetReleaseByID", err)
return
}
- if err != nil && models.IsErrReleaseNotExist(err) ||
+ if err != nil && repo_model.IsErrReleaseNotExist(err) ||
release.IsTag || release.RepoID != ctx.Repo.Repository.ID {
ctx.NotFound()
return
@@ -114,7 +115,7 @@ func ListReleases(ctx *context.APIContext) {
listOptions.PageSize = ctx.FormInt("per_page")
}
- opts := models.FindReleasesOptions{
+ opts := repo_model.FindReleasesOptions{
ListOptions: listOptions,
IncludeDrafts: ctx.Repo.AccessMode >= perm.AccessModeWrite || ctx.Repo.UnitAccessMode(unit.TypeReleases) >= perm.AccessModeWrite,
IncludeTags: false,
@@ -122,7 +123,7 @@ func ListReleases(ctx *context.APIContext) {
IsPreRelease: ctx.FormOptionalBool("pre-release"),
}
- releases, err := models.GetReleasesByRepoID(ctx.Repo.Repository.ID, opts)
+ releases, err := repo_model.GetReleasesByRepoID(ctx.Repo.Repository.ID, opts)
if err != nil {
ctx.Error(http.StatusInternalServerError, "GetReleasesByRepoID", err)
return
@@ -136,7 +137,7 @@ func ListReleases(ctx *context.APIContext) {
rels[i] = convert.ToRelease(release)
}
- filteredCount, err := models.CountReleasesByRepoID(ctx.Repo.Repository.ID, opts)
+ filteredCount, err := repo_model.CountReleasesByRepoID(ctx.Repo.Repository.ID, opts)
if err != nil {
ctx.InternalServerError(err)
return
@@ -179,9 +180,9 @@ func CreateRelease(ctx *context.APIContext) {
// "409":
// "$ref": "#/responses/error"
form := web.GetForm(ctx).(*api.CreateReleaseOption)
- rel, err := models.GetRelease(ctx.Repo.Repository.ID, form.TagName)
+ rel, err := repo_model.GetRelease(ctx.Repo.Repository.ID, form.TagName)
if err != nil {
- if !models.IsErrReleaseNotExist(err) {
+ if !repo_model.IsErrReleaseNotExist(err) {
ctx.Error(http.StatusInternalServerError, "GetRelease", err)
return
}
@@ -189,7 +190,7 @@ func CreateRelease(ctx *context.APIContext) {
if len(form.Target) == 0 {
form.Target = ctx.Repo.Repository.DefaultBranch
}
- rel = &models.Release{
+ rel = &repo_model.Release{
RepoID: ctx.Repo.Repository.ID,
PublisherID: ctx.Doer.ID,
Publisher: ctx.Doer,
@@ -203,7 +204,7 @@ func CreateRelease(ctx *context.APIContext) {
Repo: ctx.Repo.Repository,
}
if err := release_service.CreateRelease(ctx.Repo.GitRepo, rel, nil, ""); err != nil {
- if models.IsErrReleaseAlreadyExist(err) {
+ if repo_model.IsErrReleaseAlreadyExist(err) {
ctx.Error(http.StatusConflict, "ReleaseAlreadyExist", err)
} else {
ctx.Error(http.StatusInternalServerError, "CreateRelease", err)
@@ -272,12 +273,12 @@ func EditRelease(ctx *context.APIContext) {
form := web.GetForm(ctx).(*api.EditReleaseOption)
id := ctx.ParamsInt64(":id")
- rel, err := models.GetReleaseByID(ctx, id)
- if err != nil && !models.IsErrReleaseNotExist(err) {
+ rel, err := repo_model.GetReleaseByID(ctx, id)
+ if err != nil && !repo_model.IsErrReleaseNotExist(err) {
ctx.Error(http.StatusInternalServerError, "GetReleaseByID", err)
return
}
- if err != nil && models.IsErrReleaseNotExist(err) ||
+ if err != nil && repo_model.IsErrReleaseNotExist(err) ||
rel.IsTag || rel.RepoID != ctx.Repo.Repository.ID {
ctx.NotFound()
return
@@ -307,7 +308,7 @@ func EditRelease(ctx *context.APIContext) {
}
// reload data from database
- rel, err = models.GetReleaseByID(ctx, id)
+ rel, err = repo_model.GetReleaseByID(ctx, id)
if err != nil {
ctx.Error(http.StatusInternalServerError, "GetReleaseByID", err)
return
@@ -350,12 +351,12 @@ func DeleteRelease(ctx *context.APIContext) {
// "$ref": "#/responses/empty"
id := ctx.ParamsInt64(":id")
- rel, err := models.GetReleaseByID(ctx, id)
- if err != nil && !models.IsErrReleaseNotExist(err) {
+ rel, err := repo_model.GetReleaseByID(ctx, id)
+ if err != nil && !repo_model.IsErrReleaseNotExist(err) {
ctx.Error(http.StatusInternalServerError, "GetReleaseByID", err)
return
}
- if err != nil && models.IsErrReleaseNotExist(err) ||
+ if err != nil && repo_model.IsErrReleaseNotExist(err) ||
rel.IsTag || rel.RepoID != ctx.Repo.Repository.ID {
ctx.NotFound()
return
diff --git a/routers/api/v1/repo/release_attachment.go b/routers/api/v1/repo/release_attachment.go
index 7b63af34c8..a469877c13 100644
--- a/routers/api/v1/repo/release_attachment.go
+++ b/routers/api/v1/repo/release_attachment.go
@@ -7,7 +7,6 @@ package repo
import (
"net/http"
- "code.gitea.io/gitea/models"
repo_model "code.gitea.io/gitea/models/repo"
"code.gitea.io/gitea/modules/context"
"code.gitea.io/gitea/modules/convert"
@@ -102,9 +101,9 @@ func ListReleaseAttachments(ctx *context.APIContext) {
// "$ref": "#/responses/AttachmentList"
releaseID := ctx.ParamsInt64(":id")
- release, err := models.GetReleaseByID(ctx, releaseID)
+ release, err := repo_model.GetReleaseByID(ctx, releaseID)
if err != nil {
- if models.IsErrReleaseNotExist(err) {
+ if repo_model.IsErrReleaseNotExist(err) {
ctx.NotFound()
return
}
@@ -172,9 +171,9 @@ func CreateReleaseAttachment(ctx *context.APIContext) {
// Check if release exists an load release
releaseID := ctx.ParamsInt64(":id")
- release, err := models.GetReleaseByID(ctx, releaseID)
+ release, err := repo_model.GetReleaseByID(ctx, releaseID)
if err != nil {
- if models.IsErrReleaseNotExist(err) {
+ if repo_model.IsErrReleaseNotExist(err) {
ctx.NotFound()
return
}
diff --git a/routers/api/v1/repo/release_tags.go b/routers/api/v1/repo/release_tags.go
index 73dee73e1a..2cb97c58a0 100644
--- a/routers/api/v1/repo/release_tags.go
+++ b/routers/api/v1/repo/release_tags.go
@@ -8,6 +8,7 @@ import (
"net/http"
"code.gitea.io/gitea/models"
+ repo_model "code.gitea.io/gitea/models/repo"
"code.gitea.io/gitea/modules/context"
"code.gitea.io/gitea/modules/convert"
releaseservice "code.gitea.io/gitea/services/release"
@@ -44,9 +45,9 @@ func GetReleaseByTag(ctx *context.APIContext) {
tag := ctx.Params(":tag")
- release, err := models.GetRelease(ctx.Repo.Repository.ID, tag)
+ release, err := repo_model.GetRelease(ctx.Repo.Repository.ID, tag)
if err != nil {
- if models.IsErrReleaseNotExist(err) {
+ if repo_model.IsErrReleaseNotExist(err) {
ctx.NotFound()
return
}
@@ -97,9 +98,9 @@ func DeleteReleaseByTag(ctx *context.APIContext) {
tag := ctx.Params(":tag")
- release, err := models.GetRelease(ctx.Repo.Repository.ID, tag)
+ release, err := repo_model.GetRelease(ctx.Repo.Repository.ID, tag)
if err != nil {
- if models.IsErrReleaseNotExist(err) {
+ if repo_model.IsErrReleaseNotExist(err) {
ctx.NotFound()
return
}
diff --git a/routers/api/v1/repo/repo.go b/routers/api/v1/repo/repo.go
index cdd1f7d5c4..d28b56cab6 100644
--- a/routers/api/v1/repo/repo.go
+++ b/routers/api/v1/repo/repo.go
@@ -11,7 +11,6 @@ import (
"strings"
"time"
- "code.gitea.io/gitea/models"
"code.gitea.io/gitea/models/db"
"code.gitea.io/gitea/models/organization"
"code.gitea.io/gitea/models/perm"
@@ -232,7 +231,7 @@ func CreateUserRepo(ctx *context.APIContext, owner *user_model.User, opt api.Cre
if opt.AutoInit && opt.Readme == "" {
opt.Readme = "Default"
}
- repo, err := repo_service.CreateRepository(ctx.Doer, owner, models.CreateRepoOptions{
+ repo, err := repo_service.CreateRepository(ctx.Doer, owner, repo_module.CreateRepoOptions{
Name: opt.Name,
Description: opt.Description,
IssueLabels: opt.IssueLabels,
diff --git a/routers/api/v1/repo/tag.go b/routers/api/v1/repo/tag.go
index 433d823c7e..f0f8503996 100644
--- a/routers/api/v1/repo/tag.go
+++ b/routers/api/v1/repo/tag.go
@@ -10,6 +10,7 @@ import (
"net/http"
"code.gitea.io/gitea/models"
+ repo_model "code.gitea.io/gitea/models/repo"
"code.gitea.io/gitea/modules/context"
"code.gitea.io/gitea/modules/convert"
api "code.gitea.io/gitea/modules/structs"
@@ -249,9 +250,9 @@ func DeleteTag(ctx *context.APIContext) {
// "$ref": "#/responses/conflict"
tagName := ctx.Params("*")
- tag, err := models.GetRelease(ctx.Repo.Repository.ID, tagName)
+ tag, err := repo_model.GetRelease(ctx.Repo.Repository.ID, tagName)
if err != nil {
- if models.IsErrReleaseNotExist(err) {
+ if repo_model.IsErrReleaseNotExist(err) {
ctx.NotFound()
return
}
diff --git a/routers/api/v1/repo/teams.go b/routers/api/v1/repo/teams.go
index 47c69d722b..f485f2086e 100644
--- a/routers/api/v1/repo/teams.go
+++ b/routers/api/v1/repo/teams.go
@@ -12,6 +12,7 @@ import (
"code.gitea.io/gitea/models/organization"
"code.gitea.io/gitea/modules/context"
"code.gitea.io/gitea/modules/convert"
+ org_service "code.gitea.io/gitea/services/org"
)
// ListTeams list a repository's teams
@@ -199,7 +200,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 = models.AddRepository(team, ctx.Repo.Repository)
+ err = org_service.TeamAddRepository(team, ctx.Repo.Repository)
} else {
if !repoHasTeam {
ctx.Error(http.StatusUnprocessableEntity, "notAdded", fmt.Errorf("team '%s' was not added to repo", team.Name))
diff --git a/routers/api/v1/repo/wiki.go b/routers/api/v1/repo/wiki.go
index d423bddbbd..82542d1ab8 100644
--- a/routers/api/v1/repo/wiki.go
+++ b/routers/api/v1/repo/wiki.go
@@ -10,7 +10,7 @@ import (
"net/http"
"net/url"
- "code.gitea.io/gitea/models"
+ repo_model "code.gitea.io/gitea/models/repo"
"code.gitea.io/gitea/modules/context"
"code.gitea.io/gitea/modules/convert"
"code.gitea.io/gitea/modules/git"
@@ -72,9 +72,9 @@ func NewWikiPage(ctx *context.APIContext) {
form.ContentBase64 = string(content)
if err := wiki_service.AddWikiPage(ctx, ctx.Doer, ctx.Repo.Repository, wikiName, form.ContentBase64, form.Message); err != nil {
- if models.IsErrWikiReservedName(err) {
+ if repo_model.IsErrWikiReservedName(err) {
ctx.Error(http.StatusBadRequest, "IsErrWikiReservedName", err)
- } else if models.IsErrWikiAlreadyExist(err) {
+ } else if repo_model.IsErrWikiAlreadyExist(err) {
ctx.Error(http.StatusBadRequest, "IsErrWikiAlreadyExists", err)
} else {
ctx.Error(http.StatusInternalServerError, "AddWikiPage", err)
@@ -314,7 +314,7 @@ func ListWikiPages(ctx *context.APIContext) {
}
wikiName, err := wiki_service.FilenameToName(entry.Name())
if err != nil {
- if models.IsErrWikiInvalidFileName(err) {
+ if repo_model.IsErrWikiInvalidFileName(err) {
continue
}
ctx.Error(http.StatusInternalServerError, "WikiFilenameToName", err)
diff --git a/routers/api/v1/swagger/user.go b/routers/api/v1/swagger/user.go
index a4d5201236..857bdc2a14 100644
--- a/routers/api/v1/swagger/user.go
+++ b/routers/api/v1/swagger/user.go
@@ -5,7 +5,7 @@
package swagger
import (
- "code.gitea.io/gitea/models"
+ activities_model "code.gitea.io/gitea/models/activities"
api "code.gitea.io/gitea/modules/structs"
)
@@ -40,7 +40,7 @@ type swaggerModelEditUserOption struct {
// swagger:response UserHeatmapData
type swaggerResponseUserHeatmapData struct {
// in:body
- Body []models.UserHeatmapData `json:"body"`
+ Body []activities_model.UserHeatmapData `json:"body"`
}
// UserSettings
diff --git a/routers/api/v1/user/app.go b/routers/api/v1/user/app.go
index 0d2e8401cc..a94db79239 100644
--- a/routers/api/v1/user/app.go
+++ b/routers/api/v1/user/app.go
@@ -11,8 +11,7 @@ import (
"net/http"
"strconv"
- "code.gitea.io/gitea/models"
- "code.gitea.io/gitea/models/auth"
+ auth_model "code.gitea.io/gitea/models/auth"
"code.gitea.io/gitea/modules/context"
"code.gitea.io/gitea/modules/convert"
api "code.gitea.io/gitea/modules/structs"
@@ -45,14 +44,14 @@ func ListAccessTokens(ctx *context.APIContext) {
// "200":
// "$ref": "#/responses/AccessTokenList"
- opts := models.ListAccessTokensOptions{UserID: ctx.Doer.ID, ListOptions: utils.GetListOptions(ctx)}
+ opts := auth_model.ListAccessTokensOptions{UserID: ctx.Doer.ID, ListOptions: utils.GetListOptions(ctx)}
- count, err := models.CountAccessTokens(opts)
+ count, err := auth_model.CountAccessTokens(opts)
if err != nil {
ctx.InternalServerError(err)
return
}
- tokens, err := models.ListAccessTokens(opts)
+ tokens, err := auth_model.ListAccessTokens(opts)
if err != nil {
ctx.InternalServerError(err)
return
@@ -98,12 +97,12 @@ func CreateAccessToken(ctx *context.APIContext) {
form := web.GetForm(ctx).(*api.CreateAccessTokenOption)
- t := &models.AccessToken{
+ t := &auth_model.AccessToken{
UID: ctx.Doer.ID,
Name: form.Name,
}
- exist, err := models.AccessTokenByNameExists(t)
+ exist, err := auth_model.AccessTokenByNameExists(t)
if err != nil {
ctx.InternalServerError(err)
return
@@ -113,7 +112,7 @@ func CreateAccessToken(ctx *context.APIContext) {
return
}
- if err := models.NewAccessToken(t); err != nil {
+ if err := auth_model.NewAccessToken(t); err != nil {
ctx.Error(http.StatusInternalServerError, "NewAccessToken", err)
return
}
@@ -155,7 +154,7 @@ func DeleteAccessToken(ctx *context.APIContext) {
tokenID, _ := strconv.ParseInt(token, 0, 64)
if tokenID == 0 {
- tokens, err := models.ListAccessTokens(models.ListAccessTokensOptions{
+ tokens, err := auth_model.ListAccessTokens(auth_model.ListAccessTokensOptions{
Name: token,
UserID: ctx.Doer.ID,
})
@@ -180,8 +179,8 @@ func DeleteAccessToken(ctx *context.APIContext) {
return
}
- if err := models.DeleteAccessTokenByID(tokenID, ctx.Doer.ID); err != nil {
- if models.IsErrAccessTokenNotExist(err) {
+ if err := auth_model.DeleteAccessTokenByID(tokenID, ctx.Doer.ID); err != nil {
+ if auth_model.IsErrAccessTokenNotExist(err) {
ctx.NotFound()
} else {
ctx.Error(http.StatusInternalServerError, "DeleteAccessTokenByID", err)
@@ -213,7 +212,7 @@ func CreateOauth2Application(ctx *context.APIContext) {
data := web.GetForm(ctx).(*api.CreateOAuth2ApplicationOptions)
- app, err := auth.CreateOAuth2Application(ctx, auth.CreateOAuth2ApplicationOptions{
+ app, err := auth_model.CreateOAuth2Application(ctx, auth_model.CreateOAuth2ApplicationOptions{
Name: data.Name,
UserID: ctx.Doer.ID,
RedirectURIs: data.RedirectURIs,
@@ -252,7 +251,7 @@ func ListOauth2Applications(ctx *context.APIContext) {
// "200":
// "$ref": "#/responses/OAuth2ApplicationList"
- apps, total, err := auth.ListOAuth2Applications(ctx.Doer.ID, utils.GetListOptions(ctx))
+ apps, total, err := auth_model.ListOAuth2Applications(ctx.Doer.ID, utils.GetListOptions(ctx))
if err != nil {
ctx.Error(http.StatusInternalServerError, "ListOAuth2Applications", err)
return
@@ -288,8 +287,8 @@ func DeleteOauth2Application(ctx *context.APIContext) {
// "404":
// "$ref": "#/responses/notFound"
appID := ctx.ParamsInt64(":id")
- if err := auth.DeleteOAuth2Application(appID, ctx.Doer.ID); err != nil {
- if auth.IsErrOAuthApplicationNotFound(err) {
+ if err := auth_model.DeleteOAuth2Application(appID, ctx.Doer.ID); err != nil {
+ if auth_model.IsErrOAuthApplicationNotFound(err) {
ctx.NotFound()
} else {
ctx.Error(http.StatusInternalServerError, "DeleteOauth2ApplicationByID", err)
@@ -320,9 +319,9 @@ func GetOauth2Application(ctx *context.APIContext) {
// "404":
// "$ref": "#/responses/notFound"
appID := ctx.ParamsInt64(":id")
- app, err := auth.GetOAuth2ApplicationByID(ctx, appID)
+ app, err := auth_model.GetOAuth2ApplicationByID(ctx, appID)
if err != nil {
- if auth.IsErrOauthClientIDInvalid(err) || auth.IsErrOAuthApplicationNotFound(err) {
+ if auth_model.IsErrOauthClientIDInvalid(err) || auth_model.IsErrOAuthApplicationNotFound(err) {
ctx.NotFound()
} else {
ctx.Error(http.StatusInternalServerError, "GetOauth2ApplicationByID", err)
@@ -363,14 +362,14 @@ func UpdateOauth2Application(ctx *context.APIContext) {
data := web.GetForm(ctx).(*api.CreateOAuth2ApplicationOptions)
- app, err := auth.UpdateOAuth2Application(auth.UpdateOAuth2ApplicationOptions{
+ app, err := auth_model.UpdateOAuth2Application(auth_model.UpdateOAuth2ApplicationOptions{
Name: data.Name,
UserID: ctx.Doer.ID,
ID: appID,
RedirectURIs: data.RedirectURIs,
})
if err != nil {
- if auth.IsErrOauthClientIDInvalid(err) || auth.IsErrOAuthApplicationNotFound(err) {
+ if auth_model.IsErrOauthClientIDInvalid(err) || auth_model.IsErrOAuthApplicationNotFound(err) {
ctx.NotFound()
} else {
ctx.Error(http.StatusInternalServerError, "UpdateOauth2ApplicationByID", err)
diff --git a/routers/api/v1/user/user.go b/routers/api/v1/user/user.go
index 2a3cb15c0f..69197aef23 100644
--- a/routers/api/v1/user/user.go
+++ b/routers/api/v1/user/user.go
@@ -8,7 +8,7 @@ package user
import (
"net/http"
- "code.gitea.io/gitea/models"
+ activities_model "code.gitea.io/gitea/models/activities"
user_model "code.gitea.io/gitea/models/user"
"code.gitea.io/gitea/modules/context"
"code.gitea.io/gitea/modules/convert"
@@ -139,7 +139,7 @@ func GetUserHeatmapData(ctx *context.APIContext) {
// "404":
// "$ref": "#/responses/notFound"
- heatmap, err := models.GetUserHeatmapDataByUser(ctx.ContextUser, ctx.Doer)
+ heatmap, err := activities_model.GetUserHeatmapDataByUser(ctx.ContextUser, ctx.Doer)
if err != nil {
ctx.Error(http.StatusInternalServerError, "GetUserHeatmapDataByUser", err)
return