[Refactor] Move APIFormat functions into convert package (#12856)

* USER APIFormat -> ToUser

* Migrate more and mark APIFormat deprecated

* models.Comment APIFormat() -> convert.ToComment

* models.Release APIFormat() -> convert.ToRelease

* models.Attachments APIFormat() -> convert.ToReleaseAttachments

* models.CommitStatus APIFormat() -> convert.ToCommitStatus

* finish migration to convert.ToUser

* Move Test

* Imprufe Test

* fix test

Co-authored-by: techknowlogick <techknowlogick@gitea.io>
This commit is contained in:
6543 2020-10-17 06:23:08 +02:00 committed by GitHub
parent 131278ff22
commit d453533beb
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
28 changed files with 234 additions and 208 deletions

View file

@ -9,6 +9,7 @@ import (
"code.gitea.io/gitea/models"
"code.gitea.io/gitea/modules/context"
"code.gitea.io/gitea/modules/convert"
"code.gitea.io/gitea/modules/log"
"code.gitea.io/gitea/modules/setting"
api "code.gitea.io/gitea/modules/structs"
@ -62,7 +63,7 @@ func GetReleaseAttachment(ctx *context.APIContext) {
return
}
// FIXME Should prove the existence of the given repo, but results in unnecessary database requests
ctx.JSON(http.StatusOK, attach.APIFormat())
ctx.JSON(http.StatusOK, convert.ToReleaseAttachment(attach))
}
// ListReleaseAttachments lists all attachments of the release
@ -107,7 +108,7 @@ func ListReleaseAttachments(ctx *context.APIContext) {
ctx.Error(http.StatusInternalServerError, "LoadAttributes", err)
return
}
ctx.JSON(http.StatusOK, release.APIFormat().Attachments)
ctx.JSON(http.StatusOK, convert.ToRelease(release).Attachments)
}
// CreateReleaseAttachment creates an attachment and saves the given file
@ -203,7 +204,7 @@ func CreateReleaseAttachment(ctx *context.APIContext) {
return
}
ctx.JSON(http.StatusCreated, attach.APIFormat())
ctx.JSON(http.StatusCreated, convert.ToReleaseAttachment(attach))
}
// EditReleaseAttachment updates the given attachment
@ -267,7 +268,7 @@ func EditReleaseAttachment(ctx *context.APIContext, form api.EditAttachmentOptio
if err := models.UpdateAttachment(attach); err != nil {
ctx.Error(http.StatusInternalServerError, "UpdateAttachment", attach)
}
ctx.JSON(http.StatusCreated, attach.APIFormat())
ctx.JSON(http.StatusCreated, convert.ToReleaseAttachment(attach))
}
// DeleteReleaseAttachment delete a given attachment