mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2025-05-31 20:02:09 +00:00
Replace convert.To with APIFormat calls
This commit is contained in:
parent
3f7f4852ef
commit
dccb0c15b9
21 changed files with 79 additions and 225 deletions
|
@ -13,7 +13,6 @@ import (
|
|||
"github.com/gogits/gogs/models"
|
||||
"github.com/gogits/gogs/modules/context"
|
||||
"github.com/gogits/gogs/modules/setting"
|
||||
"github.com/gogits/gogs/routers/api/v1/convert"
|
||||
)
|
||||
|
||||
func ListIssues(ctx *context.APIContext) {
|
||||
|
@ -28,7 +27,12 @@ func ListIssues(ctx *context.APIContext) {
|
|||
|
||||
apiIssues := make([]*api.Issue, len(issues))
|
||||
for i := range issues {
|
||||
apiIssues[i] = convert.ToIssue(issues[i])
|
||||
// FIXME: use IssueList to improve performance.
|
||||
if err = issues[i].LoadAttributes(); err != nil {
|
||||
ctx.Error(500, "LoadAttributes", err)
|
||||
return
|
||||
}
|
||||
apiIssues[i] = issues[i].APIFormat()
|
||||
}
|
||||
|
||||
ctx.SetLinkHeader(ctx.Repo.Repository.NumIssues, setting.UI.IssuePagingNum)
|
||||
|
@ -46,13 +50,13 @@ func GetIssue(ctx *context.APIContext) {
|
|||
return
|
||||
}
|
||||
|
||||
ctx.JSON(200, convert.ToIssue(issue))
|
||||
ctx.JSON(200, issue.APIFormat())
|
||||
}
|
||||
|
||||
func CreateIssue(ctx *context.APIContext, form api.CreateIssueOption) {
|
||||
issue := &models.Issue{
|
||||
RepoID: ctx.Repo.Repository.ID,
|
||||
Title: form.Title,
|
||||
Title: form.Title,
|
||||
PosterID: ctx.User.ID,
|
||||
Poster: ctx.User,
|
||||
Content: form.Body,
|
||||
|
@ -83,7 +87,7 @@ func CreateIssue(ctx *context.APIContext, form api.CreateIssueOption) {
|
|||
|
||||
if form.Closed {
|
||||
if err := issue.ChangeStatus(ctx.User, ctx.Repo.Repository, true); err != nil {
|
||||
ctx.Error(500, "issue.ChangeStatus", err)
|
||||
ctx.Error(500, "ChangeStatus", err)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
@ -95,7 +99,7 @@ func CreateIssue(ctx *context.APIContext, form api.CreateIssueOption) {
|
|||
ctx.Error(500, "GetIssueByID", err)
|
||||
return
|
||||
}
|
||||
ctx.JSON(201, convert.ToIssue(issue))
|
||||
ctx.JSON(201, issue.APIFormat())
|
||||
}
|
||||
|
||||
func EditIssue(ctx *context.APIContext, form api.EditIssueOption) {
|
||||
|
@ -164,5 +168,5 @@ func EditIssue(ctx *context.APIContext, form api.EditIssueOption) {
|
|||
ctx.Error(500, "GetIssueByID", err)
|
||||
return
|
||||
}
|
||||
ctx.JSON(201, convert.ToIssue(issue))
|
||||
ctx.JSON(201, issue.APIFormat())
|
||||
}
|
||||
|
|
|
@ -9,7 +9,6 @@ import (
|
|||
|
||||
"github.com/gogits/gogs/models"
|
||||
"github.com/gogits/gogs/modules/context"
|
||||
"github.com/gogits/gogs/routers/api/v1/convert"
|
||||
)
|
||||
|
||||
func ListIssueLabels(ctx *context.APIContext) {
|
||||
|
@ -25,7 +24,7 @@ func ListIssueLabels(ctx *context.APIContext) {
|
|||
|
||||
apiLabels := make([]*api.Label, len(issue.Labels))
|
||||
for i := range issue.Labels {
|
||||
apiLabels[i] = convert.ToLabel(issue.Labels[i])
|
||||
apiLabels[i] = issue.Labels[i].APIFormat()
|
||||
}
|
||||
ctx.JSON(200, &apiLabels)
|
||||
}
|
||||
|
@ -65,7 +64,7 @@ func AddIssueLabels(ctx *context.APIContext, form api.IssueLabelsOption) {
|
|||
|
||||
apiLabels := make([]*api.Label, len(labels))
|
||||
for i := range labels {
|
||||
apiLabels[i] = convert.ToLabel(labels[i])
|
||||
apiLabels[i] = issue.Labels[i].APIFormat()
|
||||
}
|
||||
ctx.JSON(200, &apiLabels)
|
||||
}
|
||||
|
@ -139,7 +138,7 @@ func ReplaceIssueLabels(ctx *context.APIContext, form api.IssueLabelsOption) {
|
|||
|
||||
apiLabels := make([]*api.Label, len(labels))
|
||||
for i := range labels {
|
||||
apiLabels[i] = convert.ToLabel(labels[i])
|
||||
apiLabels[i] = issue.Labels[i].APIFormat()
|
||||
}
|
||||
ctx.JSON(200, &apiLabels)
|
||||
}
|
||||
|
|
|
@ -9,7 +9,6 @@ import (
|
|||
|
||||
"github.com/gogits/gogs/models"
|
||||
"github.com/gogits/gogs/modules/context"
|
||||
"github.com/gogits/gogs/routers/api/v1/convert"
|
||||
)
|
||||
|
||||
func ListLabels(ctx *context.APIContext) {
|
||||
|
@ -21,7 +20,7 @@ func ListLabels(ctx *context.APIContext) {
|
|||
|
||||
apiLabels := make([]*api.Label, len(labels))
|
||||
for i := range labels {
|
||||
apiLabels[i] = convert.ToLabel(labels[i])
|
||||
apiLabels[i] = labels[i].APIFormat()
|
||||
}
|
||||
ctx.JSON(200, &apiLabels)
|
||||
}
|
||||
|
@ -37,7 +36,7 @@ func GetLabel(ctx *context.APIContext) {
|
|||
return
|
||||
}
|
||||
|
||||
ctx.JSON(200, convert.ToLabel(label))
|
||||
ctx.JSON(200, label.APIFormat())
|
||||
}
|
||||
|
||||
func CreateLabel(ctx *context.APIContext, form api.CreateLabelOption) {
|
||||
|
@ -55,7 +54,7 @@ func CreateLabel(ctx *context.APIContext, form api.CreateLabelOption) {
|
|||
ctx.Error(500, "NewLabel", err)
|
||||
return
|
||||
}
|
||||
ctx.JSON(201, convert.ToLabel(label))
|
||||
ctx.JSON(201, label.APIFormat())
|
||||
}
|
||||
|
||||
func EditLabel(ctx *context.APIContext, form api.EditLabelOption) {
|
||||
|
@ -84,7 +83,7 @@ func EditLabel(ctx *context.APIContext, form api.EditLabelOption) {
|
|||
ctx.Handle(500, "UpdateLabel", err)
|
||||
return
|
||||
}
|
||||
ctx.JSON(200, convert.ToLabel(label))
|
||||
ctx.JSON(200, label.APIFormat())
|
||||
}
|
||||
|
||||
func DeleteLabel(ctx *context.APIContext) {
|
||||
|
|
|
@ -93,12 +93,12 @@ func ListMyRepos(ctx *context.APIContext) {
|
|||
|
||||
repos := make([]*api.Repository, numOwnRepos+len(accessibleRepos))
|
||||
for i := range ownRepos {
|
||||
repos[i] = convert.ToRepository(ctx.User, ownRepos[i], api.Permission{true, true, true})
|
||||
repos[i] = ownRepos[i].APIFormat(&api.Permission{true, true, true})
|
||||
}
|
||||
i := numOwnRepos
|
||||
|
||||
for repo, access := range accessibleRepos {
|
||||
repos[i] = convert.ToRepository(repo.Owner, repo, api.Permission{
|
||||
repos[i] = repo.APIFormat(&api.Permission{
|
||||
Admin: access >= models.ACCESS_MODE_ADMIN,
|
||||
Push: access >= models.ACCESS_MODE_WRITE,
|
||||
Pull: true,
|
||||
|
@ -135,7 +135,7 @@ func CreateUserRepo(ctx *context.APIContext, owner *models.User, opt api.CreateR
|
|||
return
|
||||
}
|
||||
|
||||
ctx.JSON(201, convert.ToRepository(owner, repo, api.Permission{true, true, true}))
|
||||
ctx.JSON(201, repo.APIFormat(&api.Permission{true, true, true}))
|
||||
}
|
||||
|
||||
// https://github.com/gogits/go-gogs-client/wiki/Repositories#create
|
||||
|
@ -235,7 +235,7 @@ func Migrate(ctx *context.APIContext, form auth.MigrateRepoForm) {
|
|||
}
|
||||
|
||||
log.Trace("Repository migrated: %s/%s", ctxUser.Name, form.RepoName)
|
||||
ctx.JSON(201, convert.ToRepository(ctxUser, repo, api.Permission{true, true, true}))
|
||||
ctx.JSON(201, repo.APIFormat(&api.Permission{true, true, true}))
|
||||
}
|
||||
|
||||
func parseOwnerAndRepo(ctx *context.APIContext) (*models.User, *models.Repository) {
|
||||
|
@ -264,12 +264,12 @@ func parseOwnerAndRepo(ctx *context.APIContext) (*models.User, *models.Repositor
|
|||
|
||||
// https://github.com/gogits/go-gogs-client/wiki/Repositories#get
|
||||
func Get(ctx *context.APIContext) {
|
||||
owner, repo := parseOwnerAndRepo(ctx)
|
||||
_, repo := parseOwnerAndRepo(ctx)
|
||||
if ctx.Written() {
|
||||
return
|
||||
}
|
||||
|
||||
ctx.JSON(200, convert.ToRepository(owner, repo, api.Permission{true, true, true}))
|
||||
ctx.JSON(200, repo.APIFormat(&api.Permission{true, true, true}))
|
||||
}
|
||||
|
||||
// https://github.com/gogits/go-gogs-client/wiki/Repositories#delete
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue