diff --git a/frontend/components/accountsSidebar.vue b/frontend/components/accountsSidebar.vue index 4d0a6e2..c724799 100644 --- a/frontend/components/accountsSidebar.vue +++ b/frontend/components/accountsSidebar.vue @@ -168,7 +168,7 @@ diff --git a/frontend/constants.js b/frontend/constants.js new file mode 100644 index 0000000..f0d6885 --- /dev/null +++ b/frontend/constants.js @@ -0,0 +1 @@ +export const unallocatedMoneyAcc = '00000000-0000-0000-0000-000000000001' diff --git a/frontend/router.js b/frontend/router.js index 3857448..1847373 100644 --- a/frontend/router.js +++ b/frontend/router.js @@ -1,7 +1,9 @@ import { createRouter, createWebHistory } from 'vue-router' +import budgetDashboard from './components/budgetDashboard.vue' + const routes = [ - { component: null, name: 'budget', path: '/' }, + { component: budgetDashboard, name: 'budget', path: '/' }, { component: null, name: 'account-transactions', path: '/accounts/:id' }, ] diff --git a/pkg/api/account.go b/pkg/api/account.go index 7187eb4..9c6d323 100644 --- a/pkg/api/account.go +++ b/pkg/api/account.go @@ -136,11 +136,11 @@ func (a apiServer) handleTransferMoney(w http.ResponseWriter, r *http.Request) { a.errorResponse(w, err, "transferring money", http.StatusInternalServerError) return } - } - - if err = a.dbc.TransferMoneyWithCategory(from, to, amount, category); err != nil { - a.errorResponse(w, err, "transferring money", http.StatusInternalServerError) - return + } else { + if err = a.dbc.TransferMoneyWithCategory(from, to, amount, category); err != nil { + a.errorResponse(w, err, "transferring money", http.StatusInternalServerError) + return + } } w.WriteHeader(http.StatusNoContent) diff --git a/pkg/api/transaction.go b/pkg/api/transaction.go index c7346cd..71a18ae 100644 --- a/pkg/api/transaction.go +++ b/pkg/api/transaction.go @@ -82,12 +82,18 @@ func (a apiServer) handleListTransactionsByAccount(w http.ResponseWriter, r *htt return } - var since time.Time + var ( + since time.Time + until = time.Now() + ) if v, err := time.Parse(time.RFC3339, r.URL.Query().Get("since")); err == nil { since = v } + if v, err := time.Parse(time.RFC3339, r.URL.Query().Get("until")); err == nil { + until = v + } - txs, err := a.dbc.ListTransactionsByAccount(accid, since) + txs, err := a.dbc.ListTransactionsByAccount(accid, since, until) if err != nil { a.errorResponse(w, err, "getting transactions", http.StatusInternalServerError) return diff --git a/pkg/database/database.go b/pkg/database/database.go index 475d758..bc2f9ef 100644 --- a/pkg/database/database.go +++ b/pkg/database/database.go @@ -226,10 +226,10 @@ func (c *Client) ListAccountsByType(at AccountType, showHidden bool) (a []Accoun // ListTransactionsByAccount retrieves all transactions for an account // or category -func (c *Client) ListTransactionsByAccount(acc uuid.UUID, since time.Time) (txs []Transaction, err error) { +func (c *Client) ListTransactionsByAccount(acc uuid.UUID, since, until time.Time) (txs []Transaction, err error) { if err = c.retryRead(func(db *gorm.DB) error { return db. - Where("time >= ?", since). + Where("time >= ? and time <= ?", since, until). Find(&txs, "account = ? OR category = ?", acc, acc). Error }); err != nil { diff --git a/pkg/database/database_test.go b/pkg/database/database_test.go index 5c63508..a137ec5 100644 --- a/pkg/database/database_test.go +++ b/pkg/database/database_test.go @@ -187,11 +187,11 @@ func TestTransactions(t *testing.T) { checkAcctBal(bals, UnallocatedMoney, 500) // List transactions - txs, err := dbc.ListTransactionsByAccount(tb1.ID, time.Time{}) + txs, err := dbc.ListTransactionsByAccount(tb1.ID, time.Time{}, time.Now()) require.NoError(t, err) assert.Len(t, txs, 4) - txs, err = dbc.ListTransactionsByAccount(UnallocatedMoney, time.Time{}) + txs, err = dbc.ListTransactionsByAccount(UnallocatedMoney, time.Time{}, time.Now()) require.NoError(t, err) assert.Len(t, txs, 2) @@ -232,7 +232,7 @@ func TestTransactions(t *testing.T) { require.Error(t, err) // List transactions - txs, err = dbc.ListTransactionsByAccount(tb1.ID, time.Time{}) + txs, err = dbc.ListTransactionsByAccount(tb1.ID, time.Time{}, time.Now()) require.NoError(t, err) assert.Len(t, txs, 3) }