From 3169d341d2e63b4a0301ebed2419f97fde70f269 Mon Sep 17 00:00:00 2001 From: Dan Anglin Date: Wed, 26 Apr 2023 11:23:48 +0100 Subject: [PATCH] refactor: change Status.Order to Status.Position Change Status.Order to Status.Position, and the ByStatusOrder type to ByStatusPosition to make it clearer that status' are ordered by their position on the Kanban board. --- internal/board/board.go | 12 ++--- internal/board/status.go | 44 ++++++++--------- internal/board/status_lifecycle_test.go | 8 ++-- internal/db/database_test.go | 64 ++++++++++++------------- 4 files changed, 64 insertions(+), 64 deletions(-) diff --git a/internal/board/board.go b/internal/board/board.go index 880ce66..1716c12 100644 --- a/internal/board/board.go +++ b/internal/board/board.go @@ -84,7 +84,7 @@ func (b *Board) StatusList() ([]Status, error) { statuses[ind] = status } - sort.Sort(ByStatusOrder(statuses)) + sort.Sort(ByStatusPosition(statuses)) return statuses, nil } @@ -117,10 +117,10 @@ type StatusArgs struct { // CreateStatus creates a status in the db. func (b *Board) CreateStatus(args StatusArgs) error { status := Status{ - ID: -1, - Name: args.Name, - Order: args.Order, - CardIds: nil, + ID: -1, + Name: args.Name, + Position: args.Order, + CardIds: nil, } if _, err := db.Write(b.db, db.StatusBucket, &status); err != nil { @@ -147,7 +147,7 @@ func (b *Board) UpdateStatus(args UpdateStatusArgs) error { } if args.Order > 0 { - status.Order = args.Order + status.Position = args.Order } if _, err := db.Write(b.db, db.StatusBucket, &status); err != nil { diff --git a/internal/board/status.go b/internal/board/status.go index 6a1ab83..ec7aecc 100644 --- a/internal/board/status.go +++ b/internal/board/status.go @@ -6,10 +6,10 @@ import ( // Status represents the status of the Kanban board. type Status struct { - ID int - Name string - CardIds []int - Order int + ID int + Name string + CardIds []int + Position int } // UpdateID updates the ID of the Status value. @@ -79,41 +79,41 @@ func (s *Status) RemoveCardID(cardID int) { s.CardIds = append(s.CardIds[:ind], s.CardIds[ind+1:]...) } -// ByStatusOrder implements sort.Interface for []Status based on the Order field. -type ByStatusOrder []Status +// ByStatusPosition implements sort.Interface for []Status based on the status' position on the Kanban board. +type ByStatusPosition []Status -func (s ByStatusOrder) Len() int { +func (s ByStatusPosition) Len() int { return len(s) } -func (s ByStatusOrder) Swap(i, j int) { +func (s ByStatusPosition) Swap(i, j int) { s[i], s[j] = s[j], s[i] } -func (s ByStatusOrder) Less(i, j int) bool { - return s[i].Order < s[j].Order +func (s ByStatusPosition) Less(i, j int) bool { + return s[i].Position < s[j].Position } // defaultStatusList returns the default list of statuses. func defaultStatusList() []Status { return []Status{ { - ID: -1, - Name: "To Do", - Order: 1, - CardIds: nil, + ID: -1, + Name: "To Do", + Position: 1, + CardIds: nil, }, { - ID: -1, - Name: "Doing", - Order: 2, - CardIds: nil, + ID: -1, + Name: "Doing", + Position: 2, + CardIds: nil, }, { - ID: -1, - Name: "Done", - Order: 3, - CardIds: nil, + ID: -1, + Name: "Done", + Position: 3, + CardIds: nil, }, } } diff --git a/internal/board/status_lifecycle_test.go b/internal/board/status_lifecycle_test.go index fcef679..a72e5b1 100644 --- a/internal/board/status_lifecycle_test.go +++ b/internal/board/status_lifecycle_test.go @@ -103,10 +103,10 @@ func testUpdateStatus(kanban board.Board, statusID int, newName string) func(t * } want := board.Status{ - ID: statusID, - Name: newName, - CardIds: nil, - Order: 2, + ID: statusID, + Name: newName, + CardIds: nil, + Position: 2, } if !reflect.DeepEqual(status, want) { diff --git a/internal/db/database_test.go b/internal/db/database_test.go index c362ed6..8afea26 100644 --- a/internal/db/database_test.go +++ b/internal/db/database_test.go @@ -81,28 +81,28 @@ func testWriteStatusList(t *testing.T, database *bolt.DB) { newStatusList := []board.Status{ { - ID: -1, - Name: "Backlog", - CardIds: []int{1, 14, 9, 10}, - Order: 1, + ID: -1, + Name: "Backlog", + CardIds: []int{1, 14, 9, 10}, + Position: 1, }, { - ID: -1, - Name: "Next", - CardIds: []int{2, 5, 12}, - Order: 2, + ID: -1, + Name: "Next", + CardIds: []int{2, 5, 12}, + Position: 2, }, { - ID: -1, - Name: "In progress", - CardIds: []int{3, 14}, - Order: 3, + ID: -1, + Name: "In progress", + CardIds: []int{3, 14}, + Position: 3, }, { - ID: -1, - Name: "Finished!", - CardIds: []int{4, 6, 7, 8, 11, 13}, - Order: 4, + ID: -1, + Name: "Finished!", + CardIds: []int{4, 6, 7, 8, 11, 13}, + Position: 4, }, } @@ -143,28 +143,28 @@ func testReadStatusList(t *testing.T, database *bolt.DB) { want := []board.Status{ { - ID: 1, - Name: "Backlog", - CardIds: []int{1, 14, 9, 10}, - Order: 1, + ID: 1, + Name: "Backlog", + CardIds: []int{1, 14, 9, 10}, + Position: 1, }, { - ID: 2, - Name: "Next", - CardIds: []int{2, 5, 12}, - Order: 2, + ID: 2, + Name: "Next", + CardIds: []int{2, 5, 12}, + Position: 2, }, { - ID: 3, - Name: "In progress", - CardIds: []int{3, 14}, - Order: 3, + ID: 3, + Name: "In progress", + CardIds: []int{3, 14}, + Position: 3, }, { - ID: 4, - Name: "Finished!", - CardIds: []int{4, 6, 7, 8, 11, 13}, - Order: 4, + ID: 4, + Name: "Finished!", + CardIds: []int{4, 6, 7, 8, 11, 13}, + Position: 4, }, }