API endpoints for stars
This commit is contained in:
parent
871c964ef7
commit
0834e492c0
5 changed files with 138 additions and 34 deletions
|
@ -8,6 +8,7 @@ import (
|
|||
"fmt"
|
||||
"strings"
|
||||
|
||||
"code.gitea.io/gitea/models"
|
||||
"code.gitea.io/gitea/modules/base"
|
||||
"code.gitea.io/gitea/modules/log"
|
||||
"code.gitea.io/gitea/modules/setting"
|
||||
|
@ -70,3 +71,33 @@ func APIContexter() macaron.Handler {
|
|||
c.Map(ctx)
|
||||
}
|
||||
}
|
||||
|
||||
// ExtractOwnerAndRepo returns a handler that populates the `Repo.Owner` and
|
||||
// `Repo.Repository` fields of an APIContext
|
||||
func ExtractOwnerAndRepo() macaron.Handler {
|
||||
return func(ctx *APIContext) {
|
||||
owner, err := models.GetUserByName(ctx.Params(":username"))
|
||||
if err != nil {
|
||||
if models.IsErrUserNotExist(err) {
|
||||
ctx.Error(422, "", err)
|
||||
} else {
|
||||
ctx.Error(500, "GetUserByName", err)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
repo, err := models.GetRepositoryByName(owner.ID, ctx.Params(":reponame"))
|
||||
if err != nil {
|
||||
if models.IsErrRepoNotExist(err) {
|
||||
ctx.Status(404)
|
||||
} else {
|
||||
ctx.Error(500, "GetRepositoryByName", err)
|
||||
}
|
||||
return
|
||||
}
|
||||
ctx.Repo.Owner = owner
|
||||
ctx.Data["Owner"] = owner
|
||||
ctx.Repo.Repository = repo
|
||||
ctx.Data["Repository"] = repo
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue