checkpoint: added functionality to delete statuses
This commit is contained in:
parent
f116562a5f
commit
87afaf0741
3 changed files with 40 additions and 10 deletions
|
@ -160,11 +160,11 @@ type UpdateStatusArgs struct {
|
|||
StatusArgs
|
||||
}
|
||||
|
||||
// UpdateStatus modifies an existing status in the db.
|
||||
// UpdateStatus modifies an existing status in the database.
|
||||
func (b *Board) UpdateStatus(args UpdateStatusArgs) error {
|
||||
status, err := b.Status(args.StatusID)
|
||||
if err != nil {
|
||||
return fmt.Errorf("unable to retrieve the status from the db. %w", err)
|
||||
return fmt.Errorf("unable to retrieve the status from the database. %w", err)
|
||||
}
|
||||
|
||||
if len(args.Name) > 0 {
|
||||
|
@ -182,10 +182,25 @@ func (b *Board) UpdateStatus(args UpdateStatusArgs) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
// TODO: Finish implementation.
|
||||
// func (b *Board) DeleteStatus() error {
|
||||
// return nil
|
||||
// }
|
||||
// DeleteStatus deletes a status from the database.
|
||||
// A status can only be deleted if it does not contain any cards.
|
||||
// TODO: Create two test cases for this function.
|
||||
func (b *Board) DeleteStatus(statusID int) error {
|
||||
status, err := b.Status(statusID)
|
||||
if err != nil {
|
||||
return fmt.Errorf("unable to retrieve the status from the database; %w", err)
|
||||
}
|
||||
|
||||
if len(status.CardIds) > 0 {
|
||||
return StatusNotEmptyError{ID: statusID}
|
||||
}
|
||||
|
||||
if err := db.Delete(b.db, db.StatusBucket, statusID); err != nil {
|
||||
return fmt.Errorf("unable to delete the status from the database; %w", err)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
type MoveToStatusArgs struct {
|
||||
CardID int
|
||||
|
@ -346,18 +361,18 @@ type DeleteCardArgs struct {
|
|||
// DeleteCard deletes a card from the database.
|
||||
func (b *Board) DeleteCard(args DeleteCardArgs) error {
|
||||
if err := db.Delete(b.db, db.CardBucket, args.CardID); err != nil {
|
||||
return fmt.Errorf("unable to delete the card from the database, %w", err)
|
||||
return fmt.Errorf("unable to delete the card from the database; %w", err)
|
||||
}
|
||||
|
||||
status, err := b.Status(args.StatusID)
|
||||
if err != nil {
|
||||
return fmt.Errorf("unable to read Status '%d' from the database, %w", args.StatusID, err)
|
||||
return fmt.Errorf("unable to read Status '%d' from the database; %w", args.StatusID, err)
|
||||
}
|
||||
|
||||
status.RemoveCardID(args.CardID)
|
||||
|
||||
if _, err := db.Write(b.db, db.StatusBucket, &status); err != nil {
|
||||
return fmt.Errorf("unable to update the status in the database, %w", err)
|
||||
return fmt.Errorf("unable to update the status in the database; %w", err)
|
||||
}
|
||||
|
||||
return nil
|
||||
|
|
|
@ -19,6 +19,14 @@ func (e StatusNotExistError) Error() string {
|
|||
return fmt.Sprintf("status ID '%d' does not exist in the database", e.ID)
|
||||
}
|
||||
|
||||
type StatusNotEmptyError struct {
|
||||
ID int
|
||||
}
|
||||
|
||||
func (e StatusNotEmptyError) Error() string {
|
||||
return fmt.Sprintf("status ID '%d' must contain no cards before deletion", e.ID)
|
||||
}
|
||||
|
||||
// Status represents the status of the Kanban board.
|
||||
type Status struct {
|
||||
ID int
|
||||
|
|
|
@ -53,7 +53,8 @@ func TestStatusLifecycle(t *testing.T) {
|
|||
t.Run("Test Status Update (In Progress)", testUpdateStatus(kanban, 2, 2, "In Progress"))
|
||||
t.Run("Test Status Update (Backlog)", testUpdateStatus(kanban, 1, 1, "Backlog"))
|
||||
|
||||
// (TODO: Rearranging statuses still needs to be implemented) Rearrange the board so the order is To Do, On Hold, In Progress, Done
|
||||
// (TODO: Rearranging statuses still needs to be implemented)
|
||||
// Rearrange the board so the order is: Backlog, Next, In Progress, On Hold, Done
|
||||
|
||||
t.Logf("Let us now try moving a card from one status to another...")
|
||||
t.Run("Test Move Card To Status", testMoveCardToStatus(kanban))
|
||||
|
@ -202,3 +203,9 @@ func testMoveCardToStatus(kanban board.Board) func(t *testing.T) {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
func testDeleteStatus(kanban board.Board) func(t *testing.T) {
|
||||
return func(t *testing.T) {
|
||||
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue