feat: move a card between statuses #3
9 changed files with 49 additions and 30 deletions
4
go.mod
4
go.mod
|
@ -1,11 +1,11 @@
|
|||
module codeflow.dananglin.me.uk/apollo/canal
|
||||
|
||||
go 1.19
|
||||
go 1.20
|
||||
|
||||
require (
|
||||
github.com/gdamore/tcell/v2 v2.6.0
|
||||
github.com/magefile/mage v1.14.0
|
||||
github.com/rivo/tview v0.0.0-20230226195229-47e7db7885b4
|
||||
github.com/rivo/tview v0.0.0-20230320095235-84f9c0ff9de8
|
||||
go.etcd.io/bbolt v1.3.7
|
||||
)
|
||||
|
||||
|
|
4
go.sum
4
go.sum
|
@ -10,8 +10,8 @@ github.com/magefile/mage v1.14.0/go.mod h1:z5UZb/iS3GoOSn0JgWuiw7dxlurVYTu+/jHXq
|
|||
github.com/mattn/go-runewidth v0.0.14 h1:+xnbZSEeDbOIg5/mE6JF0w6n9duR1l3/WmbinWVwUuU=
|
||||
github.com/mattn/go-runewidth v0.0.14/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w=
|
||||
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
||||
github.com/rivo/tview v0.0.0-20230226195229-47e7db7885b4 h1:tj6c++jeZxE3+Z+8+3/HOY/KpqaVt1tZ8i6sNRmjQ1M=
|
||||
github.com/rivo/tview v0.0.0-20230226195229-47e7db7885b4/go.mod h1:nVwGv4MP47T0jvlk7KuTTjjuSmrGO4JF0iaiNt4bufE=
|
||||
github.com/rivo/tview v0.0.0-20230320095235-84f9c0ff9de8 h1:wthS/rREJ6WlALtQ3Ysp4Cty/qiY2LNslV90U71bNg0=
|
||||
github.com/rivo/tview v0.0.0-20230320095235-84f9c0ff9de8/go.mod h1:nVwGv4MP47T0jvlk7KuTTjjuSmrGO4JF0iaiNt4bufE=
|
||||
github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc=
|
||||
github.com/rivo/uniseg v0.4.3 h1:utMvzDsuh3suAEnhH0RdHmoPbU648o6CvXxTx4SBMOw=
|
||||
github.com/rivo/uniseg v0.4.3/go.mod h1:FN3SvrM+Zdj16jyLfmOkMNblXMcoc8DfTHruCPUcx88=
|
||||
|
|
|
@ -1,17 +0,0 @@
|
|||
package board
|
||||
|
||||
type CardArgs struct {
|
||||
NewTitle string
|
||||
NewContent string
|
||||
}
|
||||
|
||||
type UpdateCardArgs struct {
|
||||
CardID int
|
||||
CardArgs
|
||||
}
|
||||
|
||||
type UpdateCardStatusArgs struct {
|
||||
CardID int
|
||||
OldStatusID int
|
||||
NewStatusID int
|
||||
}
|
|
@ -87,6 +87,11 @@ func DeleteStatus(db *bolt.DB) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
type CardArgs struct {
|
||||
NewTitle string
|
||||
NewContent string
|
||||
}
|
||||
|
||||
// CreateCard creates a card in the database.
|
||||
func CreateCard(db *bolt.DB, args CardArgs) error {
|
||||
statusList, err := ReadStatusList(db)
|
||||
|
@ -167,7 +172,12 @@ func ReadCardList(db *bolt.DB, ids []int) ([]Card, error) {
|
|||
return cards, nil
|
||||
}
|
||||
|
||||
// UpdateCard modifies an existing card and saves the modification to the database.
|
||||
type UpdateCardArgs struct {
|
||||
CardID int
|
||||
CardArgs
|
||||
}
|
||||
|
||||
// UpdateCard modifies an existing card in the database.
|
||||
func UpdateCard(db *bolt.DB, args UpdateCardArgs) error {
|
||||
card, err := ReadCard(db, args.CardID)
|
||||
if err != nil {
|
||||
|
@ -189,6 +199,12 @@ func UpdateCard(db *bolt.DB, args UpdateCardArgs) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
type UpdateCardStatusArgs struct {
|
||||
CardID int
|
||||
OldStatusID int
|
||||
NewStatusID int
|
||||
}
|
||||
|
||||
// UpdateCardStatus moves a card between statuses.
|
||||
// TODO: finish implementation.
|
||||
func UpdateCardStatus(db *bolt.DB, args UpdateCardStatusArgs) error {
|
||||
|
|
|
@ -51,7 +51,12 @@ func TestCardLifecycle(t *testing.T) {
|
|||
func testCreateCard(t *testing.T, db *bolt.DB, title, content string, wantID int) {
|
||||
t.Helper()
|
||||
|
||||
if err := board.CreateCard(db, title, content); err != nil {
|
||||
args := board.CardArgs{
|
||||
NewTitle: title,
|
||||
NewContent: content,
|
||||
}
|
||||
|
||||
if err := board.CreateCard(db, args); err != nil {
|
||||
t.Fatalf("Unable to create the test card, %s.", err)
|
||||
}
|
||||
|
||||
|
@ -101,7 +106,15 @@ func testReadCard(t *testing.T, db *bolt.DB, cardID int, wantTitle, wantContent
|
|||
func testUpdateCard(t *testing.T, db *bolt.DB, cardID int, newTitle, newContent string) {
|
||||
t.Helper()
|
||||
|
||||
if err := board.UpdateCard(db, cardID, newTitle, newContent); err != nil {
|
||||
args := board.UpdateCardArgs{
|
||||
CardID: cardID,
|
||||
CardArgs: board.CardArgs{
|
||||
NewTitle: newTitle,
|
||||
NewContent: newContent,
|
||||
},
|
||||
}
|
||||
|
||||
if err := board.UpdateCard(db, args); err != nil {
|
||||
t.Fatalf("Unable to update the test card, %s", err)
|
||||
}
|
||||
|
||||
|
@ -126,7 +139,15 @@ func testUpdateCard(t *testing.T, db *bolt.DB, cardID int, newTitle, newContent
|
|||
func testUpdateCardContent(t *testing.T, db *bolt.DB, cardID int, expectedTitle, newContent string) {
|
||||
t.Helper()
|
||||
|
||||
if err := board.UpdateCard(db, cardID, "", newContent); err != nil {
|
||||
args := board.UpdateCardArgs{
|
||||
CardID: cardID,
|
||||
CardArgs: board.CardArgs{
|
||||
NewTitle: "",
|
||||
NewContent: newContent,
|
||||
},
|
||||
}
|
||||
|
||||
if err := board.UpdateCard(db, args); err != nil {
|
||||
t.Fatalf("Unable to update the test card, %s", err)
|
||||
}
|
||||
|
||||
|
|
|
@ -68,7 +68,7 @@ func Read(db *bolt.DB, bucketName string, id int) ([]byte, error) {
|
|||
|
||||
return nil
|
||||
}); err != nil {
|
||||
return []byte{}, fmt.Errorf("error while reading the Bolt item from the database, %w", err)
|
||||
return nil, fmt.Errorf("error while reading the Bolt item from the database, %w", err)
|
||||
}
|
||||
|
||||
return data, nil
|
||||
|
@ -95,7 +95,7 @@ func ReadMany(db *bolt.DB, bucketName string, ids []int) ([][]byte, error) {
|
|||
return nil
|
||||
})
|
||||
if err != nil {
|
||||
return output, fmt.Errorf("error while retrieving the data from the database, %w", err)
|
||||
return nil, fmt.Errorf("error while retrieving the data from the database, %w", err)
|
||||
}
|
||||
|
||||
return output, nil
|
||||
|
@ -125,7 +125,7 @@ func ReadAll(db *bolt.DB, bucketName string) ([][]byte, error) {
|
|||
return nil
|
||||
})
|
||||
if err != nil {
|
||||
return output, fmt.Errorf("error while loading statuses from the database, %w", err)
|
||||
return nil, fmt.Errorf("error while loading statuses from the database, %w", err)
|
||||
}
|
||||
|
||||
return output, nil
|
||||
|
|
|
@ -147,7 +147,7 @@ func (a *App) newCard(title, content string) error {
|
|||
|
||||
// TODO: Move 'Add' to the centre of the app
|
||||
// TODO: Customize list primitive or create a new one
|
||||
// TODO: If customizing exisiing list primitive, wrap list around a column type. Add statusID to it.
|
||||
// TODO: If customizing existing list primitive, wrap list around a column type. Add statusID to it.
|
||||
// TODO: Update card status (card ID, oldStatus, newStatus)
|
||||
|
||||
//func viewCard() error {
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
//go:build mage
|
||||
// +build mage
|
||||
|
||||
package main
|
||||
|
BIN
main
BIN
main
Binary file not shown.
Loading…
Reference in a new issue