feat: delete cards #6

Closed
dananglin wants to merge 35 commits from delete-cards into main
4 changed files with 64 additions and 64 deletions
Showing only changes of commit 3169d341d2 - Show all commits

View file

@ -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 {

View file

@ -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,
},
}
}

View file

@ -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) {

View file

@ -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,
},
}