mirror of
https://codeberg.org/davrot/forgejo.git
synced 2025-05-28 12:00:01 +02:00
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>
This commit is contained in:
parent
462306e263
commit
a4bfef265d
335 changed files with 4191 additions and 3654 deletions
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue