diff --git a/go.mod b/go.mod index 28f3143..54142d5 100644 --- a/go.mod +++ b/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 ) diff --git a/go.sum b/go.sum index 9f8a0bc..9ebc3c1 100644 --- a/go.sum +++ b/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= diff --git a/internal/board/args.go b/internal/board/args.go deleted file mode 100644 index 342cd1f..0000000 --- a/internal/board/args.go +++ /dev/null @@ -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 -} diff --git a/internal/board/board.go b/internal/board/board.go index 36113bb..d1f6415 100644 --- a/internal/board/board.go +++ b/internal/board/board.go @@ -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 { diff --git a/internal/board/board_test.go b/internal/board/board_test.go index 50c4852..7c494c8 100644 --- a/internal/board/board_test.go +++ b/internal/board/board_test.go @@ -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) } diff --git a/internal/database/database.go b/internal/database/database.go index 0b0503e..5c9a6d5 100644 --- a/internal/database/database.go +++ b/internal/database/database.go @@ -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 diff --git a/internal/ui/app.go b/internal/ui/app.go index 635e68e..aba1b9b 100644 --- a/internal/ui/app.go +++ b/internal/ui/app.go @@ -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 { diff --git a/magefile.go b/magefiles/magefile.go similarity index 98% rename from magefile.go rename to magefiles/magefile.go index 6bc532a..ca28bdb 100644 --- a/magefile.go +++ b/magefiles/magefile.go @@ -1,5 +1,4 @@ //go:build mage -// +build mage package main diff --git a/main b/main deleted file mode 100755 index 0f7b70f..0000000 Binary files a/main and /dev/null differ