This commit is contained in:
Lunny Xiao 2024-05-04 17:51:41 +08:00
parent 0aa451b9ab
commit be61c91492
No known key found for this signature in database
GPG Key ID: C3B7C91B632F738A
3 changed files with 20 additions and 20 deletions

View File

@ -5,6 +5,7 @@ package issues
import (
"context"
"database/sql"
"fmt"
"code.gitea.io/gitea/models/db"
@ -131,23 +132,22 @@ func IssueAssignOrRemoveProject(ctx context.Context, issue *Issue, doer *user_mo
return nil
}
var maxSorting int64
has, err := db.GetEngine(ctx).Select("Max(sorting)").Table("project_issue").
var maxSorting sql.NullInt64
if _, err := db.GetEngine(ctx).Select("Max(sorting)").Table("project_issue").
Where("project_id=?", newProjectID).
And("project_board_id=?", newColumnID).
Get(&maxSorting)
if err != nil {
Get(&maxSorting); err != nil {
return err
}
if has {
maxSorting++
if maxSorting.Valid {
maxSorting.Int64++
}
return db.Insert(ctx, &project_model.ProjectIssue{
IssueID: issue.ID,
ProjectID: newProjectID,
ProjectBoardID: newColumnID,
Sorting: maxSorting,
Sorting: maxSorting.Int64,
})
})
}

View File

@ -5,6 +5,7 @@ package project
import (
"context"
"database/sql"
"errors"
"fmt"
"regexp"
@ -184,14 +185,13 @@ func NewBoard(ctx context.Context, board *Board) error {
}
if totalColumns > 0 {
var maxSorting int8
has, err := db.GetEngine(ctx).Select("Max(sorting)").Table("project_board").
Where("project_id=?", board.ProjectID).Get(&maxSorting)
if err != nil {
var maxSorting sql.NullByte
if _, err := db.GetEngine(ctx).Select("Max(sorting)").Table("project_board").
Where("project_id=?", board.ProjectID).Get(&maxSorting); err != nil {
return err
}
if has {
board.Sorting = maxSorting + 1
if maxSorting.Valid {
board.Sorting = int8(maxSorting.Byte) + 1
}
}

View File

@ -5,6 +5,7 @@ package project
import (
"context"
"database/sql"
"fmt"
"code.gitea.io/gitea/models/db"
@ -109,16 +110,15 @@ func (b *Board) moveIssuesToAnotherColumn(ctx context.Context, newColumn *Board)
return nil
}
var maxSorting int8
has, err := db.GetEngine(ctx).Select("Max(sorting)").Table("project_issue").
var maxSorting sql.NullByte
if _, err := db.GetEngine(ctx).Select("Max(sorting)").Table("project_issue").
Where("project_id=?", newColumn.ProjectID).
And("project_board_id=?", newColumn.ID).
Get(&maxSorting)
if err != nil {
Get(&maxSorting); err != nil {
return err
}
if has {
maxSorting++
if maxSorting.Valid {
maxSorting.Byte++
}
issues, err := b.GetIssues(ctx)
@ -132,7 +132,7 @@ func (b *Board) moveIssuesToAnotherColumn(ctx context.Context, newColumn *Board)
return db.WithTx(ctx, func(ctx context.Context) error {
for i, issue := range issues {
issue.ProjectBoardID = newColumn.ID
issue.Sorting = int64(maxSorting) + int64(i)
issue.Sorting = int64(maxSorting.Byte) + int64(i)
if _, err := db.GetEngine(ctx).ID(issue.ID).Cols("project_board_id", "sorting").Update(issue); err != nil {
return err
}