1
1
mirror of https://github.com/go-gitea/gitea synced 2025-07-22 18:28:37 +00:00

[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
28 changed files with 234 additions and 208 deletions

View File

@@ -10,6 +10,7 @@ import (
"code.gitea.io/gitea/models"
"code.gitea.io/gitea/modules/context"
"code.gitea.io/gitea/modules/convert"
api "code.gitea.io/gitea/modules/structs"
"code.gitea.io/gitea/routers/api/v1/utils"
)
@@ -75,7 +76,7 @@ func GetIssueCommentReactions(ctx *context.APIContext) {
var result []api.Reaction
for _, r := range reactions {
result = append(result, api.Reaction{
User: r.User.APIFormat(),
User: convert.ToUser(r.User, ctx.IsSigned, false),
Reaction: r.Type,
Created: r.CreatedUnix.AsTime(),
})
@@ -193,7 +194,7 @@ func changeIssueCommentReaction(ctx *context.APIContext, form api.EditReactionOp
ctx.Error(http.StatusForbidden, err.Error(), err)
} else if models.IsErrReactionAlreadyExist(err) {
ctx.JSON(http.StatusOK, api.Reaction{
User: ctx.User.APIFormat(),
User: convert.ToUser(ctx.User, true, true),
Reaction: reaction.Type,
Created: reaction.CreatedUnix.AsTime(),
})
@@ -204,7 +205,7 @@ func changeIssueCommentReaction(ctx *context.APIContext, form api.EditReactionOp
}
ctx.JSON(http.StatusCreated, api.Reaction{
User: ctx.User.APIFormat(),
User: convert.ToUser(ctx.User, true, true),
Reaction: reaction.Type,
Created: reaction.CreatedUnix.AsTime(),
})
@@ -289,7 +290,7 @@ func GetIssueReactions(ctx *context.APIContext) {
var result []api.Reaction
for _, r := range reactions {
result = append(result, api.Reaction{
User: r.User.APIFormat(),
User: convert.ToUser(r.User, ctx.IsSigned, false),
Reaction: r.Type,
Created: r.CreatedUnix.AsTime(),
})
@@ -402,7 +403,7 @@ func changeIssueReaction(ctx *context.APIContext, form api.EditReactionOption, i
ctx.Error(http.StatusForbidden, err.Error(), err)
} else if models.IsErrReactionAlreadyExist(err) {
ctx.JSON(http.StatusOK, api.Reaction{
User: ctx.User.APIFormat(),
User: convert.ToUser(ctx.User, true, true),
Reaction: reaction.Type,
Created: reaction.CreatedUnix.AsTime(),
})
@@ -413,7 +414,7 @@ func changeIssueReaction(ctx *context.APIContext, form api.EditReactionOption, i
}
ctx.JSON(http.StatusCreated, api.Reaction{
User: ctx.User.APIFormat(),
User: convert.ToUser(ctx.User, true, true),
Reaction: reaction.Type,
Created: reaction.CreatedUnix.AsTime(),
})