aboutsummaryrefslogtreecommitdiff
path: root/internal/route/api
diff options
context:
space:
mode:
Diffstat (limited to 'internal/route/api')
-rw-r--r--internal/route/api/v1/api.go4
-rw-r--r--internal/route/api/v1/convert/convert.go5
-rw-r--r--internal/route/api/v1/org/org.go2
-rw-r--r--internal/route/api/v1/repo/collaborators.go6
-rw-r--r--internal/route/api/v1/repo/commits.go4
-rw-r--r--internal/route/api/v1/repo/issue.go4
-rw-r--r--internal/route/api/v1/repo/repo.go10
-rw-r--r--internal/route/api/v1/user/email.go6
-rw-r--r--internal/route/api/v1/user/key.go2
-rw-r--r--internal/route/api/v1/user/user.go2
10 files changed, 23 insertions, 22 deletions
diff --git a/internal/route/api/v1/api.go b/internal/route/api/v1/api.go
index 0a17e657..79d346fe 100644
--- a/internal/route/api/v1/api.go
+++ b/internal/route/api/v1/api.go
@@ -37,7 +37,7 @@ func repoAssignment() macaron.Handler {
if c.IsLogged && c.User.LowerName == strings.ToLower(username) {
owner = c.User
} else {
- owner, err = db.GetUserByName(username)
+ owner, err = db.Users.GetByUsername(c.Req.Context(), username)
if err != nil {
c.NotFoundOrError(err, "get user by name")
return
@@ -91,7 +91,7 @@ func orgAssignment(args ...bool) macaron.Handler {
var err error
if assignOrg {
- c.Org.Organization, err = db.GetUserByName(c.Params(":orgname"))
+ c.Org.Organization, err = db.Users.GetByUsername(c.Req.Context(), c.Params(":orgname"))
if err != nil {
c.NotFoundOrError(err, "get organization by name")
return
diff --git a/internal/route/api/v1/convert/convert.go b/internal/route/api/v1/convert/convert.go
index 04d4df33..a91432dd 100644
--- a/internal/route/api/v1/convert/convert.go
+++ b/internal/route/api/v1/convert/convert.go
@@ -5,6 +5,7 @@
package convert
import (
+ "context"
"fmt"
"github.com/unknwon/com"
@@ -44,12 +45,12 @@ func ToTag(b *db.Tag, c *git.Commit) *Tag {
func ToCommit(c *git.Commit) *api.PayloadCommit {
authorUsername := ""
- author, err := db.GetUserByEmail(c.Author.Email)
+ author, err := db.Users.GetByEmail(context.TODO(), c.Author.Email)
if err == nil {
authorUsername = author.Name
}
committerUsername := ""
- committer, err := db.GetUserByEmail(c.Committer.Email)
+ committer, err := db.Users.GetByEmail(context.TODO(), c.Committer.Email)
if err == nil {
committerUsername = committer.Name
}
diff --git a/internal/route/api/v1/org/org.go b/internal/route/api/v1/org/org.go
index cefe5cc6..2f6b4b70 100644
--- a/internal/route/api/v1/org/org.go
+++ b/internal/route/api/v1/org/org.go
@@ -45,7 +45,7 @@ func CreateOrgForUser(c *context.APIContext, apiForm api.CreateOrgOption, user *
func listUserOrgs(c *context.APIContext, u *db.User, all bool) {
orgs, err := db.Orgs.List(
c.Req.Context(),
- db.ListOrgOptions{
+ db.ListOrgsOptions{
MemberID: u.ID,
IncludePrivateMembers: all,
},
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
diff --git a/internal/route/api/v1/user/email.go b/internal/route/api/v1/user/email.go
index 5584803e..cda2a0a4 100644
--- a/internal/route/api/v1/user/email.go
+++ b/internal/route/api/v1/user/email.go
@@ -38,7 +38,7 @@ func AddEmail(c *context.APIContext, form api.CreateEmailOption) {
emails := make([]*db.EmailAddress, len(form.Emails))
for i := range form.Emails {
emails[i] = &db.EmailAddress{
- UID: c.User.ID,
+ UserID: c.User.ID,
Email: form.Emails[i],
IsActivated: !conf.Auth.RequireEmailConfirmation,
}
@@ -69,8 +69,8 @@ func DeleteEmail(c *context.APIContext, form api.CreateEmailOption) {
emails := make([]*db.EmailAddress, len(form.Emails))
for i := range form.Emails {
emails[i] = &db.EmailAddress{
- UID: c.User.ID,
- Email: form.Emails[i],
+ UserID: c.User.ID,
+ Email: form.Emails[i],
}
}
diff --git a/internal/route/api/v1/user/key.go b/internal/route/api/v1/user/key.go
index 344c7ca2..c80e3bf0 100644
--- a/internal/route/api/v1/user/key.go
+++ b/internal/route/api/v1/user/key.go
@@ -18,7 +18,7 @@ import (
)
func GetUserByParamsName(c *context.APIContext, name string) *db.User {
- user, err := db.GetUserByName(c.Params(name))
+ user, err := db.Users.GetByUsername(c.Req.Context(), c.Params(name))
if err != nil {
c.NotFoundOrError(err, "get user by name")
return nil
diff --git a/internal/route/api/v1/user/user.go b/internal/route/api/v1/user/user.go
index 5852f660..10d82b9a 100644
--- a/internal/route/api/v1/user/user.go
+++ b/internal/route/api/v1/user/user.go
@@ -55,7 +55,7 @@ func Search(c *context.APIContext) {
}
func GetInfo(c *context.APIContext) {
- u, err := db.GetUserByName(c.Params(":username"))
+ u, err := db.Users.GetByUsername(c.Req.Context(), c.Params(":username"))
if err != nil {
c.NotFoundOrError(err, "get user by name")
return