Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve GetBoards and getDefaultBoard #22981

Merged
merged 3 commits into from Apr 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 6 additions & 6 deletions models/project/board.go
Expand Up @@ -229,14 +229,14 @@ func UpdateBoard(ctx context.Context, board *Board) error {

// GetBoards fetches all boards related to a project
// if no default board set, first board is a temporary "Uncategorized" board
func GetBoards(ctx context.Context, projectID int64) (BoardList, error) {
func (p *Project) GetBoards(ctx context.Context) (BoardList, error) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Later on, we can even think about making this a LoadBoards, but that's for the future.

boards := make([]*Board, 0, 5)

if err := db.GetEngine(ctx).Where("project_id=? AND `default`=?", projectID, false).OrderBy("Sorting").Find(&boards); err != nil {
if err := db.GetEngine(ctx).Where("project_id=? AND `default`=?", p.ID, false).OrderBy("Sorting").Find(&boards); err != nil {
return nil, err
}

defaultB, err := getDefaultBoard(ctx, projectID)
defaultB, err := p.getDefaultBoard(ctx)
if err != nil {
return nil, err
}
Expand All @@ -245,9 +245,9 @@ func GetBoards(ctx context.Context, projectID int64) (BoardList, error) {
}

// getDefaultBoard return default board and create a dummy if none exist
func getDefaultBoard(ctx context.Context, projectID int64) (*Board, error) {
func (p *Project) getDefaultBoard(ctx context.Context) (*Board, error) {
var board Board
exist, err := db.GetEngine(ctx).Where("project_id=? AND `default`=?", projectID, true).Get(&board)
exist, err := db.GetEngine(ctx).Where("project_id=? AND `default`=?", p.ID, true).Get(&board)
if err != nil {
return nil, err
}
Expand All @@ -257,7 +257,7 @@ func getDefaultBoard(ctx context.Context, projectID int64) (*Board, error) {

// represents a board for issues not assigned to one
return &Board{
ProjectID: projectID,
ProjectID: p.ID,
Title: "Uncategorized",
Default: true,
}, nil
Expand Down
2 changes: 1 addition & 1 deletion routers/web/org/projects.go
Expand Up @@ -313,7 +313,7 @@ func ViewProject(ctx *context.Context) {
return
}

boards, err := project_model.GetBoards(ctx, project.ID)
boards, err := project.GetBoards(ctx)
if err != nil {
ctx.ServerError("GetProjectBoards", err)
return
Expand Down
2 changes: 1 addition & 1 deletion routers/web/repo/projects.go
Expand Up @@ -300,7 +300,7 @@ func ViewProject(ctx *context.Context) {
return
}

boards, err := project_model.GetBoards(ctx, project.ID)
boards, err := project.GetBoards(ctx)
if err != nil {
ctx.ServerError("GetProjectBoards", err)
return
Expand Down