diff options
author | Joe Chen <jc@unknwon.io> | 2022-11-05 23:33:05 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-11-05 23:33:05 +0800 |
commit | 5fb29db2db04bc128af410867f1f602320eb5d66 (patch) | |
tree | 9d0b86702d872f8f5ab7d0691e511c52f38fde34 /internal/route/api/v1/repo | |
parent | b5d47b969258f3d644ad797b29901eb607f6b94f (diff) |
refactor(db): migrate methods off and delete deprecated methods from `user.go` (#7231)
Diffstat (limited to 'internal/route/api/v1/repo')
-rw-r--r-- | internal/route/api/v1/repo/collaborators.go | 6 | ||||
-rw-r--r-- | internal/route/api/v1/repo/commits.go | 4 | ||||
-rw-r--r-- | internal/route/api/v1/repo/issue.go | 4 | ||||
-rw-r--r-- | internal/route/api/v1/repo/repo.go | 10 |
4 files changed, 12 insertions, 12 deletions
diff --git a/internal/route/api/v1/repo/collaborators.go b/internal/route/api/v1/repo/collaborators.go index c9d2ff30..4d813c07 100644 --- a/internal/route/api/v1/repo/collaborators.go +++ b/internal/route/api/v1/repo/collaborators.go @@ -28,7 +28,7 @@ func ListCollaborators(c *context.APIContext) { } func AddCollaborator(c *context.APIContext, form api.AddCollaboratorOption) { - collaborator, err := db.GetUserByName(c.Params(":collaborator")) + collaborator, err := db.Users.GetByUsername(c.Req.Context(), c.Params(":collaborator")) if err != nil { if db.IsErrUserNotExist(err) { c.Status(http.StatusUnprocessableEntity) @@ -54,7 +54,7 @@ func AddCollaborator(c *context.APIContext, form api.AddCollaboratorOption) { } func IsCollaborator(c *context.APIContext) { - collaborator, err := db.GetUserByName(c.Params(":collaborator")) + collaborator, err := db.Users.GetByUsername(c.Req.Context(), c.Params(":collaborator")) if err != nil { if db.IsErrUserNotExist(err) { c.Status(http.StatusUnprocessableEntity) @@ -72,7 +72,7 @@ func IsCollaborator(c *context.APIContext) { } func DeleteCollaborator(c *context.APIContext) { - collaborator, err := db.GetUserByName(c.Params(":collaborator")) + collaborator, err := db.Users.GetByUsername(c.Req.Context(), c.Params(":collaborator")) if err != nil { if db.IsErrUserNotExist(err) { c.Status(http.StatusUnprocessableEntity) diff --git a/internal/route/api/v1/repo/commits.go b/internal/route/api/v1/repo/commits.go index 5b3280a1..8d16c845 100644 --- a/internal/route/api/v1/repo/commits.go +++ b/internal/route/api/v1/repo/commits.go @@ -120,7 +120,7 @@ func GetReferenceSHA(c *context.APIContext) { func gitCommitToAPICommit(commit *git.Commit, c *context.APIContext) (*api.Commit, error) { // Retrieve author and committer information var apiAuthor, apiCommitter *api.User - author, err := db.GetUserByEmail(commit.Author.Email) + author, err := db.Users.GetByEmail(c.Req.Context(), commit.Author.Email) if err != nil && !db.IsErrUserNotExist(err) { return nil, err } else if err == nil { @@ -131,7 +131,7 @@ func gitCommitToAPICommit(commit *git.Commit, c *context.APIContext) (*api.Commi if commit.Committer.Email == commit.Author.Email { apiCommitter = apiAuthor } else { - committer, err := db.GetUserByEmail(commit.Committer.Email) + committer, err := db.Users.GetByEmail(c.Req.Context(), commit.Committer.Email) if err != nil && !db.IsErrUserNotExist(err) { return nil, err } else if err == nil { diff --git a/internal/route/api/v1/repo/issue.go b/internal/route/api/v1/repo/issue.go index 8d54fd35..c663a830 100644 --- a/internal/route/api/v1/repo/issue.go +++ b/internal/route/api/v1/repo/issue.go @@ -83,7 +83,7 @@ func CreateIssue(c *context.APIContext, form api.CreateIssueOption) { if c.Repo.IsWriter() { if len(form.Assignee) > 0 { - assignee, err := db.GetUserByName(form.Assignee) + assignee, err := db.Users.GetByUsername(c.Req.Context(), form.Assignee) if err != nil { if db.IsErrUserNotExist(err) { c.ErrorStatus(http.StatusUnprocessableEntity, fmt.Errorf("assignee does not exist: [name: %s]", form.Assignee)) @@ -145,7 +145,7 @@ func EditIssue(c *context.APIContext, form api.EditIssueOption) { if *form.Assignee == "" { issue.AssigneeID = 0 } else { - assignee, err := db.GetUserByName(*form.Assignee) + assignee, err := db.Users.GetByUsername(c.Req.Context(), *form.Assignee) if err != nil { if db.IsErrUserNotExist(err) { c.ErrorStatus(http.StatusUnprocessableEntity, fmt.Errorf("assignee does not exist: [name: %s]", *form.Assignee)) diff --git a/internal/route/api/v1/repo/repo.go b/internal/route/api/v1/repo/repo.go index 81341627..c0e3b612 100644 --- a/internal/route/api/v1/repo/repo.go +++ b/internal/route/api/v1/repo/repo.go @@ -32,7 +32,7 @@ func Search(c *context.APIContext) { if c.User.ID == opts.OwnerID { opts.Private = true } else { - u, err := db.GetUserByID(opts.OwnerID) + u, err := db.Users.GetByID(c.Req.Context(), opts.OwnerID) if err != nil { c.JSON(http.StatusInternalServerError, map[string]interface{}{ "ok": false, @@ -77,7 +77,7 @@ func Search(c *context.APIContext) { } func listUserRepositories(c *context.APIContext, username string) { - user, err := db.GetUserByName(username) + user, err := db.Users.GetByUsername(c.Req.Context(), username) if err != nil { c.NotFoundOrError(err, "get user by name") return @@ -209,7 +209,7 @@ func Migrate(c *context.APIContext, f form.MigrateRepo) { // Not equal means context user is an organization, // or is another user/organization if current user is admin. if f.Uid != ctxUser.ID { - org, err := db.GetUserByID(f.Uid) + org, err := db.Users.GetByID(c.Req.Context(), f.Uid) if err != nil { if db.IsErrUserNotExist(err) { c.ErrorStatus(http.StatusUnprocessableEntity, err) @@ -287,7 +287,7 @@ func Migrate(c *context.APIContext, f form.MigrateRepo) { // FIXME: inject in the handler chain func parseOwnerAndRepo(c *context.APIContext) (*db.User, *db.Repository) { - owner, err := db.GetUserByName(c.Params(":username")) + owner, err := db.Users.GetByUsername(c.Req.Context(), c.Params(":username")) if err != nil { if db.IsErrUserNotExist(err) { c.ErrorStatus(http.StatusUnprocessableEntity, err) @@ -453,7 +453,7 @@ func Releases(c *context.APIContext) { } apiReleases := make([]*api.Release, 0, len(releases)) for _, r := range releases { - publisher, err := db.GetUserByID(r.PublisherID) + publisher, err := db.Users.GetByID(c.Req.Context(), r.PublisherID) if err != nil { c.Error(err, "get release publisher") return |