diff options
author | Lunny Xiao <xiaolunwen@gmail.com> | 2021-11-24 10:49:20 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-11-24 10:49:20 +0100 |
commit | a666829a37be6f9fd98f9e7dd1767c420f7f3b32 (patch) | |
tree | 9ab1434b759a8a2cb275a83149903a823851e309 /routers/api/v1/user | |
parent | Use `*PushUpdateOptions` as receiver (#17724) (diff) | |
download | forgejo-a666829a37be6f9fd98f9e7dd1767c420f7f3b32.tar.xz forgejo-a666829a37be6f9fd98f9e7dd1767c420f7f3b32.zip |
Move user related model into models/user (#17781)
* Move user related model into models/user
* Fix lint for windows
* Fix windows lint
* Fix windows lint
* Move some tests in models
* Merge
Diffstat (limited to 'routers/api/v1/user')
-rw-r--r-- | routers/api/v1/user/follower.go | 13 | ||||
-rw-r--r-- | routers/api/v1/user/helper.go | 9 | ||||
-rw-r--r-- | routers/api/v1/user/key.go | 7 | ||||
-rw-r--r-- | routers/api/v1/user/repo.go | 3 | ||||
-rw-r--r-- | routers/api/v1/user/settings.go | 4 | ||||
-rw-r--r-- | routers/api/v1/user/star.go | 3 | ||||
-rw-r--r-- | routers/api/v1/user/user.go | 7 | ||||
-rw-r--r-- | routers/api/v1/user/watch.go | 3 |
8 files changed, 26 insertions, 23 deletions
diff --git a/routers/api/v1/user/follower.go b/routers/api/v1/user/follower.go index edf3cea3ea..1eacb89db2 100644 --- a/routers/api/v1/user/follower.go +++ b/routers/api/v1/user/follower.go @@ -8,7 +8,6 @@ package user import ( "net/http" - "code.gitea.io/gitea/models" user_model "code.gitea.io/gitea/models/user" "code.gitea.io/gitea/modules/context" "code.gitea.io/gitea/modules/convert" @@ -16,7 +15,7 @@ import ( "code.gitea.io/gitea/routers/api/v1/utils" ) -func responseAPIUsers(ctx *context.APIContext, users []*models.User) { +func responseAPIUsers(ctx *context.APIContext, users []*user_model.User) { apiUsers := make([]*api.User, len(users)) for i := range users { apiUsers[i] = convert.ToUser(users[i], ctx.User) @@ -24,8 +23,8 @@ func responseAPIUsers(ctx *context.APIContext, users []*models.User) { ctx.JSON(http.StatusOK, &apiUsers) } -func listUserFollowers(ctx *context.APIContext, u *models.User) { - users, err := models.GetUserFollowers(u, utils.GetListOptions(ctx)) +func listUserFollowers(ctx *context.APIContext, u *user_model.User) { + users, err := user_model.GetUserFollowers(u, utils.GetListOptions(ctx)) if err != nil { ctx.Error(http.StatusInternalServerError, "GetUserFollowers", err) return @@ -90,8 +89,8 @@ func ListFollowers(ctx *context.APIContext) { listUserFollowers(ctx, u) } -func listUserFollowing(ctx *context.APIContext, u *models.User) { - users, err := models.GetUserFollowing(u, utils.GetListOptions(ctx)) +func listUserFollowing(ctx *context.APIContext, u *user_model.User) { + users, err := user_model.GetUserFollowing(u, utils.GetListOptions(ctx)) if err != nil { ctx.Error(http.StatusInternalServerError, "GetUserFollowing", err) return @@ -156,7 +155,7 @@ func ListFollowing(ctx *context.APIContext) { listUserFollowing(ctx, u) } -func checkUserFollowing(ctx *context.APIContext, u *models.User, followID int64) { +func checkUserFollowing(ctx *context.APIContext, u *user_model.User, followID int64) { if user_model.IsFollowing(u.ID, followID) { ctx.Status(http.StatusNoContent) } else { diff --git a/routers/api/v1/user/helper.go b/routers/api/v1/user/helper.go index a7c2e61405..fab3ce2ae5 100644 --- a/routers/api/v1/user/helper.go +++ b/routers/api/v1/user/helper.go @@ -7,17 +7,16 @@ package user import ( "net/http" - "code.gitea.io/gitea/models" user_model "code.gitea.io/gitea/models/user" "code.gitea.io/gitea/modules/context" ) // GetUserByParamsName get user by name -func GetUserByParamsName(ctx *context.APIContext, name string) *models.User { +func GetUserByParamsName(ctx *context.APIContext, name string) *user_model.User { username := ctx.Params(name) - user, err := models.GetUserByName(username) + user, err := user_model.GetUserByName(username) if err != nil { - if models.IsErrUserNotExist(err) { + if user_model.IsErrUserNotExist(err) { if redirectUserID, err2 := user_model.LookupUserRedirect(username); err2 == nil { context.RedirectToUser(ctx.Context, username, redirectUserID) } else { @@ -32,6 +31,6 @@ func GetUserByParamsName(ctx *context.APIContext, name string) *models.User { } // GetUserByParams returns user whose name is presented in URL (":username"). -func GetUserByParams(ctx *context.APIContext) *models.User { +func GetUserByParams(ctx *context.APIContext) *user_model.User { return GetUserByParamsName(ctx, ":username") } diff --git a/routers/api/v1/user/key.go b/routers/api/v1/user/key.go index 36b1c17b89..719e1c0bdc 100644 --- a/routers/api/v1/user/key.go +++ b/routers/api/v1/user/key.go @@ -8,6 +8,7 @@ import ( "net/http" "code.gitea.io/gitea/models" + user_model "code.gitea.io/gitea/models/user" "code.gitea.io/gitea/modules/context" "code.gitea.io/gitea/modules/convert" "code.gitea.io/gitea/modules/setting" @@ -18,7 +19,7 @@ import ( ) // appendPrivateInformation appends the owner and key type information to api.PublicKey -func appendPrivateInformation(apiKey *api.PublicKey, key *models.PublicKey, defaultUser *models.User) (*api.PublicKey, error) { +func appendPrivateInformation(apiKey *api.PublicKey, key *models.PublicKey, defaultUser *user_model.User) (*api.PublicKey, error) { if key.Type == models.KeyTypeDeploy { apiKey.KeyType = "deploy" } else if key.Type == models.KeyTypeUser { @@ -27,7 +28,7 @@ func appendPrivateInformation(apiKey *api.PublicKey, key *models.PublicKey, defa if defaultUser.ID == key.OwnerID { apiKey.Owner = convert.ToUser(defaultUser, defaultUser) } else { - user, err := models.GetUserByID(key.OwnerID) + user, err := user_model.GetUserByID(key.OwnerID) if err != nil { return apiKey, err } @@ -44,7 +45,7 @@ func composePublicKeysAPILink() string { return setting.AppURL + "api/v1/user/keys/" } -func listPublicKeys(ctx *context.APIContext, user *models.User) { +func listPublicKeys(ctx *context.APIContext, user *user_model.User) { var keys []*models.PublicKey var err error var count int diff --git a/routers/api/v1/user/repo.go b/routers/api/v1/user/repo.go index 3c9a17a0be..0b0b522c15 100644 --- a/routers/api/v1/user/repo.go +++ b/routers/api/v1/user/repo.go @@ -8,6 +8,7 @@ import ( "net/http" "code.gitea.io/gitea/models" + user_model "code.gitea.io/gitea/models/user" "code.gitea.io/gitea/modules/context" "code.gitea.io/gitea/modules/convert" api "code.gitea.io/gitea/modules/structs" @@ -15,7 +16,7 @@ import ( ) // listUserRepos - List the repositories owned by the given user. -func listUserRepos(ctx *context.APIContext, u *models.User, private bool) { +func listUserRepos(ctx *context.APIContext, u *user_model.User, private bool) { opts := utils.GetListOptions(ctx) repos, count, err := models.GetUserRepositories(&models.SearchRepoOptions{ diff --git a/routers/api/v1/user/settings.go b/routers/api/v1/user/settings.go index b4548e7443..40bee56681 100644 --- a/routers/api/v1/user/settings.go +++ b/routers/api/v1/user/settings.go @@ -7,7 +7,7 @@ package user import ( "net/http" - "code.gitea.io/gitea/models" + user_model "code.gitea.io/gitea/models/user" "code.gitea.io/gitea/modules/context" "code.gitea.io/gitea/modules/convert" api "code.gitea.io/gitea/modules/structs" @@ -74,7 +74,7 @@ func UpdateUserSettings(ctx *context.APIContext) { ctx.User.KeepActivityPrivate = *form.HideActivity } - if err := models.UpdateUser(ctx.User); err != nil { + if err := user_model.UpdateUser(ctx.User); err != nil { ctx.InternalServerError(err) return } diff --git a/routers/api/v1/user/star.go b/routers/api/v1/user/star.go index f067722bfa..946ae738e9 100644 --- a/routers/api/v1/user/star.go +++ b/routers/api/v1/user/star.go @@ -10,6 +10,7 @@ import ( "code.gitea.io/gitea/models" "code.gitea.io/gitea/models/db" + user_model "code.gitea.io/gitea/models/user" "code.gitea.io/gitea/modules/context" "code.gitea.io/gitea/modules/convert" api "code.gitea.io/gitea/modules/structs" @@ -18,7 +19,7 @@ import ( // getStarredRepos returns the repos that the user with the specified userID has // starred -func getStarredRepos(user *models.User, private bool, listOptions db.ListOptions) ([]*api.Repository, error) { +func getStarredRepos(user *user_model.User, private bool, listOptions db.ListOptions) ([]*api.Repository, error) { starredRepos, err := models.GetStarredRepos(user.ID, private, listOptions) if err != nil { return nil, err diff --git a/routers/api/v1/user/user.go b/routers/api/v1/user/user.go index 8c57b1f099..bba7b7a5d1 100644 --- a/routers/api/v1/user/user.go +++ b/routers/api/v1/user/user.go @@ -9,6 +9,7 @@ import ( "net/http" "code.gitea.io/gitea/models" + user_model "code.gitea.io/gitea/models/user" "code.gitea.io/gitea/modules/context" "code.gitea.io/gitea/modules/convert" "code.gitea.io/gitea/routers/api/v1/utils" @@ -54,11 +55,11 @@ func Search(ctx *context.APIContext) { listOptions := utils.GetListOptions(ctx) - users, maxResults, err := models.SearchUsers(&models.SearchUserOptions{ + users, maxResults, err := user_model.SearchUsers(&user_model.SearchUserOptions{ Actor: ctx.User, Keyword: ctx.FormTrim("q"), UID: ctx.FormInt64("uid"), - Type: models.UserTypeIndividual, + Type: user_model.UserTypeIndividual, ListOptions: listOptions, }) if err != nil { @@ -105,7 +106,7 @@ func GetInfo(ctx *context.APIContext) { if !models.IsUserVisibleToViewer(u, ctx.User) { // fake ErrUserNotExist error message to not leak information about existence - ctx.NotFound("GetUserByName", models.ErrUserNotExist{Name: ctx.Params(":username")}) + ctx.NotFound("GetUserByName", user_model.ErrUserNotExist{Name: ctx.Params(":username")}) return } ctx.JSON(http.StatusOK, convert.ToUser(u, ctx.User)) diff --git a/routers/api/v1/user/watch.go b/routers/api/v1/user/watch.go index 3c6f8b3070..54d5e74bc0 100644 --- a/routers/api/v1/user/watch.go +++ b/routers/api/v1/user/watch.go @@ -9,6 +9,7 @@ import ( "code.gitea.io/gitea/models" "code.gitea.io/gitea/models/db" + user_model "code.gitea.io/gitea/models/user" "code.gitea.io/gitea/modules/context" "code.gitea.io/gitea/modules/convert" api "code.gitea.io/gitea/modules/structs" @@ -16,7 +17,7 @@ import ( ) // getWatchedRepos returns the repos that the user with the specified userID is watching -func getWatchedRepos(user *models.User, private bool, listOptions db.ListOptions) ([]*api.Repository, int64, error) { +func getWatchedRepos(user *user_model.User, private bool, listOptions db.ListOptions) ([]*api.Repository, int64, error) { watchedRepos, total, err := models.GetWatchedRepos(user.ID, private, listOptions) if err != nil { return nil, 0, err |