summaryrefslogtreecommitdiffstats
path: root/models/issue_user.go
diff options
context:
space:
mode:
authorLunny Xiao <xiaolunwen@gmail.com>2021-09-19 19:49:59 +0800
committerGitHub <noreply@github.com>2021-09-19 19:49:59 +0800
commita4bfef265d9e512830350635a0489c2cdcd6508f (patch)
tree1e3c2ec94276dfcb2f8ba73a2ac075ba39c4a34a /models/issue_user.go
parent462306e263db5a809dbe2cdf62e99307aeff28de (diff)
downloadgitea-a4bfef265d9e512830350635a0489c2cdcd6508f.tar.gz
gitea-a4bfef265d9e512830350635a0489c2cdcd6508f.zip
Move db related basic functions to models/db (#17075)
* Move db related basic functions to models/db * Fix lint * Fix lint * Fix test * Fix lint * Fix lint * revert unnecessary change * Fix test * Fix wrong replace string * Use *Context * Correct committer spelling and fix wrong replaced words Co-authored-by: zeripath <art27@cantab.net>
Diffstat (limited to 'models/issue_user.go')
-rw-r--r--models/issue_user.go18
1 files changed, 12 insertions, 6 deletions
diff --git a/models/issue_user.go b/models/issue_user.go
index 67a118fe57..6f9b7591cd 100644
--- a/models/issue_user.go
+++ b/models/issue_user.go
@@ -6,6 +6,8 @@ package models
import (
"fmt"
+
+ "code.gitea.io/gitea/models/db"
)
// IssueUser represents an issue-user relation.
@@ -17,7 +19,11 @@ type IssueUser struct {
IsMentioned bool
}
-func newIssueUsers(e Engine, repo *Repository, issue *Issue) error {
+func init() {
+ db.RegisterModel(new(IssueUser))
+}
+
+func newIssueUsers(e db.Engine, repo *Repository, issue *Issue) error {
assignees, err := repo.getAssignees(e)
if err != nil {
return fmt.Errorf("getAssignees: %v", err)
@@ -51,27 +57,27 @@ func newIssueUsers(e Engine, repo *Repository, issue *Issue) error {
// UpdateIssueUserByRead updates issue-user relation for reading.
func UpdateIssueUserByRead(uid, issueID int64) error {
- _, err := x.Exec("UPDATE `issue_user` SET is_read=? WHERE uid=? AND issue_id=?", true, uid, issueID)
+ _, err := db.DefaultContext().Engine().Exec("UPDATE `issue_user` SET is_read=? WHERE uid=? AND issue_id=?", true, uid, issueID)
return err
}
// UpdateIssueUsersByMentions updates issue-user pairs by mentioning.
-func UpdateIssueUsersByMentions(ctx DBContext, issueID int64, uids []int64) error {
+func UpdateIssueUsersByMentions(ctx *db.Context, issueID int64, uids []int64) error {
for _, uid := range uids {
iu := &IssueUser{
UID: uid,
IssueID: issueID,
}
- has, err := ctx.e.Get(iu)
+ has, err := ctx.Engine().Get(iu)
if err != nil {
return err
}
iu.IsMentioned = true
if has {
- _, err = ctx.e.ID(iu.ID).Cols("is_mentioned").Update(iu)
+ _, err = ctx.Engine().ID(iu.ID).Cols("is_mentioned").Update(iu)
} else {
- _, err = ctx.e.Insert(iu)
+ _, err = ctx.Engine().Insert(iu)
}
if err != nil {
return err