From be61c914920285943b0cfbd7d78c1f1a3cff9961 Mon Sep 17 00:00:00 2001 From: Lunny Xiao Date: Sat, 4 May 2024 17:51:41 +0800 Subject: [PATCH] Fix bug --- models/issues/issue_project.go | 14 +++++++------- models/project/board.go | 12 ++++++------ models/project/issue.go | 14 +++++++------- 3 files changed, 20 insertions(+), 20 deletions(-) diff --git a/models/issues/issue_project.go b/models/issues/issue_project.go index 0353dd14da..a9b9286a47 100644 --- a/models/issues/issue_project.go +++ b/models/issues/issue_project.go @@ -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, }) }) } diff --git a/models/project/board.go b/models/project/board.go index 0b119275e7..c04424e304 100644 --- a/models/project/board.go +++ b/models/project/board.go @@ -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 } } diff --git a/models/project/issue.go b/models/project/issue.go index 7e4730d987..eefa71c7cc 100644 --- a/models/project/issue.go +++ b/models/project/issue.go @@ -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 }