Improve GetBoards and getDefaultBoard (#22981)
Change `GetBoards(ctx context.Context, projectID int64)` to `(p *Project) GetBoards(ctx context.Context) (BoardList, error)` `getDefaultBoard` is same.
This commit is contained in:
parent
bedad23f9e
commit
8bc8ca1953
3 changed files with 8 additions and 8 deletions
|
@ -229,14 +229,14 @@ func UpdateBoard(ctx context.Context, board *Board) error {
|
||||||
|
|
||||||
// GetBoards fetches all boards related to a project
|
// GetBoards fetches all boards related to a project
|
||||||
// if no default board set, first board is a temporary "Uncategorized" board
|
// 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) {
|
||||||
boards := make([]*Board, 0, 5)
|
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
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
defaultB, err := getDefaultBoard(ctx, projectID)
|
defaultB, err := p.getDefaultBoard(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -245,9 +245,9 @@ func GetBoards(ctx context.Context, projectID int64) (BoardList, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// getDefaultBoard return default board and create a dummy if none exist
|
// 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
|
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 {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -257,7 +257,7 @@ func getDefaultBoard(ctx context.Context, projectID int64) (*Board, error) {
|
||||||
|
|
||||||
// represents a board for issues not assigned to one
|
// represents a board for issues not assigned to one
|
||||||
return &Board{
|
return &Board{
|
||||||
ProjectID: projectID,
|
ProjectID: p.ID,
|
||||||
Title: "Uncategorized",
|
Title: "Uncategorized",
|
||||||
Default: true,
|
Default: true,
|
||||||
}, nil
|
}, nil
|
||||||
|
|
|
@ -313,7 +313,7 @@ func ViewProject(ctx *context.Context) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
boards, err := project_model.GetBoards(ctx, project.ID)
|
boards, err := project.GetBoards(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.ServerError("GetProjectBoards", err)
|
ctx.ServerError("GetProjectBoards", err)
|
||||||
return
|
return
|
||||||
|
|
|
@ -300,7 +300,7 @@ func ViewProject(ctx *context.Context) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
boards, err := project_model.GetBoards(ctx, project.ID)
|
boards, err := project.GetBoards(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.ServerError("GetProjectBoards", err)
|
ctx.ServerError("GetProjectBoards", err)
|
||||||
return
|
return
|
||||||
|
|
Loading…
Add table
Reference in a new issue