aboutsummaryrefslogtreecommitdiffstats
path: root/routers
diff options
context:
space:
mode:
authorLunny Xiao <xiaolunwen@gmail.com>2022-03-31 17:20:39 +0800
committerGitHub <noreply@github.com>2022-03-31 17:20:39 +0800
commitd4f84f1c937e24e71aa5f05c58d440cde741450f (patch)
tree18571ad08fabe6d1090ea4d2674beab3b1c00a6e /routers
parent43332a483f7838df66e0209eb9c15d4aba3d5874 (diff)
downloadgitea-d4f84f1c937e24e71aa5f05c58d440cde741450f.tar.gz
gitea-d4f84f1c937e24e71aa5f05c58d440cde741450f.zip
Move reaction to models/issues/ (#19264)
* Move reaction to models/issues/ * Fix test * move the function * improve code * Update models/issues/reaction.go Co-authored-by: wxiaoguang <wxiaoguang@gmail.com> Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
Diffstat (limited to 'routers')
-rw-r--r--routers/api/v1/repo/issue_reaction.go25
-rw-r--r--routers/web/repo/issue.go13
2 files changed, 20 insertions, 18 deletions
diff --git a/routers/api/v1/repo/issue_reaction.go b/routers/api/v1/repo/issue_reaction.go
index 38f4bc4752..5aa7366796 100644
--- a/routers/api/v1/repo/issue_reaction.go
+++ b/routers/api/v1/repo/issue_reaction.go
@@ -9,6 +9,7 @@ import (
"net/http"
"code.gitea.io/gitea/models"
+ issues_model "code.gitea.io/gitea/models/issues"
"code.gitea.io/gitea/modules/context"
"code.gitea.io/gitea/modules/convert"
api "code.gitea.io/gitea/modules/structs"
@@ -67,12 +68,12 @@ func GetIssueCommentReactions(ctx *context.APIContext) {
return
}
- reactions, _, err := models.FindCommentReactions(comment)
+ reactions, _, err := issues_model.FindCommentReactions(comment.IssueID, comment.ID)
if err != nil {
ctx.Error(http.StatusInternalServerError, "FindCommentReactions", err)
return
}
- _, err = reactions.LoadUsers(ctx.Repo.Repository)
+ _, err = reactions.LoadUsers(ctx, ctx.Repo.Repository)
if err != nil {
ctx.Error(http.StatusInternalServerError, "ReactionList.LoadUsers()", err)
return
@@ -197,11 +198,11 @@ func changeIssueCommentReaction(ctx *context.APIContext, form api.EditReactionOp
if isCreateType {
// PostIssueCommentReaction part
- reaction, err := models.CreateCommentReaction(ctx.Doer, comment.Issue, comment, form.Reaction)
+ reaction, err := issues_model.CreateCommentReaction(ctx.Doer.ID, comment.Issue.ID, comment.ID, form.Reaction)
if err != nil {
- if models.IsErrForbiddenIssueReaction(err) {
+ if issues_model.IsErrForbiddenIssueReaction(err) {
ctx.Error(http.StatusForbidden, err.Error(), err)
- } else if models.IsErrReactionAlreadyExist(err) {
+ } else if issues_model.IsErrReactionAlreadyExist(err) {
ctx.JSON(http.StatusOK, api.Reaction{
User: convert.ToUser(ctx.Doer, ctx.Doer),
Reaction: reaction.Type,
@@ -220,7 +221,7 @@ func changeIssueCommentReaction(ctx *context.APIContext, form api.EditReactionOp
})
} else {
// DeleteIssueCommentReaction part
- err = models.DeleteCommentReaction(ctx.Doer, comment.Issue, comment, form.Reaction)
+ err = issues_model.DeleteCommentReaction(ctx.Doer.ID, comment.Issue.ID, comment.ID, form.Reaction)
if err != nil {
ctx.Error(http.StatusInternalServerError, "DeleteCommentReaction", err)
return
@@ -285,12 +286,12 @@ func GetIssueReactions(ctx *context.APIContext) {
return
}
- reactions, count, err := models.FindIssueReactions(issue, utils.GetListOptions(ctx))
+ reactions, count, err := issues_model.FindIssueReactions(issue.ID, utils.GetListOptions(ctx))
if err != nil {
ctx.Error(http.StatusInternalServerError, "FindIssueReactions", err)
return
}
- _, err = reactions.LoadUsers(ctx.Repo.Repository)
+ _, err = reactions.LoadUsers(ctx, ctx.Repo.Repository)
if err != nil {
ctx.Error(http.StatusInternalServerError, "ReactionList.LoadUsers()", err)
return
@@ -407,11 +408,11 @@ func changeIssueReaction(ctx *context.APIContext, form api.EditReactionOption, i
if isCreateType {
// PostIssueReaction part
- reaction, err := models.CreateIssueReaction(ctx.Doer, issue, form.Reaction)
+ reaction, err := issues_model.CreateIssueReaction(ctx.Doer.ID, issue.ID, form.Reaction)
if err != nil {
- if models.IsErrForbiddenIssueReaction(err) {
+ if issues_model.IsErrForbiddenIssueReaction(err) {
ctx.Error(http.StatusForbidden, err.Error(), err)
- } else if models.IsErrReactionAlreadyExist(err) {
+ } else if issues_model.IsErrReactionAlreadyExist(err) {
ctx.JSON(http.StatusOK, api.Reaction{
User: convert.ToUser(ctx.Doer, ctx.Doer),
Reaction: reaction.Type,
@@ -430,7 +431,7 @@ func changeIssueReaction(ctx *context.APIContext, form api.EditReactionOption, i
})
} else {
// DeleteIssueReaction part
- err = models.DeleteIssueReaction(ctx.Doer, issue, form.Reaction)
+ err = issues_model.DeleteIssueReaction(ctx.Doer.ID, issue.ID, form.Reaction)
if err != nil {
ctx.Error(http.StatusInternalServerError, "DeleteIssueReaction", err)
return
diff --git a/routers/web/repo/issue.go b/routers/web/repo/issue.go
index c50e773e99..486a63a9e1 100644
--- a/routers/web/repo/issue.go
+++ b/routers/web/repo/issue.go
@@ -19,6 +19,7 @@ import (
"code.gitea.io/gitea/models"
"code.gitea.io/gitea/models/db"
+ issues_model "code.gitea.io/gitea/models/issues"
"code.gitea.io/gitea/models/organization"
project_model "code.gitea.io/gitea/models/project"
repo_model "code.gitea.io/gitea/models/repo"
@@ -2349,9 +2350,9 @@ func ChangeIssueReaction(ctx *context.Context) {
switch ctx.Params(":action") {
case "react":
- reaction, err := models.CreateIssueReaction(ctx.Doer, issue, form.Content)
+ reaction, err := issues_model.CreateIssueReaction(ctx.Doer.ID, issue.ID, form.Content)
if err != nil {
- if models.IsErrForbiddenIssueReaction(err) {
+ if issues_model.IsErrForbiddenIssueReaction(err) {
ctx.ServerError("ChangeIssueReaction", err)
return
}
@@ -2367,7 +2368,7 @@ func ChangeIssueReaction(ctx *context.Context) {
log.Trace("Reaction for issue created: %d/%d/%d", ctx.Repo.Repository.ID, issue.ID, reaction.ID)
case "unreact":
- if err := models.DeleteIssueReaction(ctx.Doer, issue, form.Content); err != nil {
+ if err := issues_model.DeleteIssueReaction(ctx.Doer.ID, issue.ID, form.Content); err != nil {
ctx.ServerError("DeleteIssueReaction", err)
return
}
@@ -2451,9 +2452,9 @@ func ChangeCommentReaction(ctx *context.Context) {
switch ctx.Params(":action") {
case "react":
- reaction, err := models.CreateCommentReaction(ctx.Doer, comment.Issue, comment, form.Content)
+ reaction, err := issues_model.CreateCommentReaction(ctx.Doer.ID, comment.Issue.ID, comment.ID, form.Content)
if err != nil {
- if models.IsErrForbiddenIssueReaction(err) {
+ if issues_model.IsErrForbiddenIssueReaction(err) {
ctx.ServerError("ChangeIssueReaction", err)
return
}
@@ -2469,7 +2470,7 @@ func ChangeCommentReaction(ctx *context.Context) {
log.Trace("Reaction for comment created: %d/%d/%d/%d", ctx.Repo.Repository.ID, comment.Issue.ID, comment.ID, reaction.ID)
case "unreact":
- if err := models.DeleteCommentReaction(ctx.Doer, comment.Issue, comment, form.Content); err != nil {
+ if err := issues_model.DeleteCommentReaction(ctx.Doer.ID, comment.Issue.ID, comment.ID, form.Content); err != nil {
ctx.ServerError("DeleteCommentReaction", err)
return
}