From 2cf6b815bf52d0159d0a4f75481e99e17baaf5a3 Mon Sep 17 00:00:00 2001 From: Jan Bader Date: Sun, 27 Feb 2022 20:45:02 +0000 Subject: [PATCH] Use view everywhere --- postgres/queries/transactions.sql | 2 +- postgres/transactions.sql.go | 18 ++++++++++++------ postgres/ynab-export.go | 2 +- server/account.go | 2 +- server/reconcile.go | 11 ++++++++++- web/src/pages/Account.vue | 6 ++++-- 6 files changed, 29 insertions(+), 12 deletions(-) diff --git a/postgres/queries/transactions.sql b/postgres/queries/transactions.sql index fed2e4e..91322d6 100644 --- a/postgres/queries/transactions.sql +++ b/postgres/queries/transactions.sql @@ -1,5 +1,5 @@ -- name: GetTransaction :one -SELECT * FROM transactions +SELECT * FROM display_transactions WHERE id = $1; -- name: CreateTransaction :one diff --git a/postgres/transactions.sql.go b/postgres/transactions.sql.go index 6e7f63b..9cc9ead 100644 --- a/postgres/transactions.sql.go +++ b/postgres/transactions.sql.go @@ -127,23 +127,29 @@ func (q *Queries) GetAllTransactionsForBudget(ctx context.Context, budgetID uuid } const getTransaction = `-- name: GetTransaction :one -SELECT id, date, memo, amount, account_id, category_id, payee_id, group_id, status FROM transactions +SELECT id, date, memo, amount, group_id, status, account, payee_id, category_id, payee, category_group, category, transfer_account, budget_id, account_id FROM display_transactions WHERE id = $1 ` -func (q *Queries) GetTransaction(ctx context.Context, id uuid.UUID) (Transaction, error) { +func (q *Queries) GetTransaction(ctx context.Context, id uuid.UUID) (DisplayTransaction, error) { row := q.db.QueryRowContext(ctx, getTransaction, id) - var i Transaction + var i DisplayTransaction err := row.Scan( &i.ID, &i.Date, &i.Memo, &i.Amount, - &i.AccountID, - &i.CategoryID, - &i.PayeeID, &i.GroupID, &i.Status, + &i.Account, + &i.PayeeID, + &i.CategoryID, + &i.Payee, + &i.CategoryGroup, + &i.Category, + &i.TransferAccount, + &i.BudgetID, + &i.AccountID, ) return i, err } diff --git a/postgres/ynab-export.go b/postgres/ynab-export.go index 35d822b..7b52f2c 100644 --- a/postgres/ynab-export.go +++ b/postgres/ynab-export.go @@ -110,7 +110,7 @@ func (ynab *YNABExport) ExportTransactions(context context.Context, w io.Writer) return nil } -func GetTransactionRow(transaction GetAllTransactionsForBudgetRow) []string { +func GetTransactionRow(transaction DisplayTransaction) []string { row := []string{ transaction.Account, "", // Flag diff --git a/server/account.go b/server/account.go index 59eab6a..0c057af 100644 --- a/server/account.go +++ b/server/account.go @@ -33,7 +33,7 @@ func (h *Handler) transactionsForAccount(c *gin.Context) { type TransactionsResponse struct { Account postgres.Account - Transactions []postgres.GetTransactionsForAccountRow + Transactions []postgres.DisplayTransaction } type EditAccountRequest struct { diff --git a/server/reconcile.go b/server/reconcile.go index c8caf05..681bba3 100644 --- a/server/reconcile.go +++ b/server/reconcile.go @@ -5,6 +5,7 @@ import ( "fmt" "net/http" + "git.javil.eu/jacob1123/budgeteer/postgres" "git.javil.eu/jacob1123/budgeteer/postgres/numeric" "github.com/gin-gonic/gin" "github.com/google/uuid" @@ -15,6 +16,11 @@ type ReconcileTransactionsRequest struct { ReconcilationTransactionAmount numeric.Numeric `json:"reconcilationTransactionAmount"` } +type ReconcileTransactionsResponse struct { + Message string + ReconcilationTransaction []postgres.GetTransactionsForAccountRow +} + func (h *Handler) reconcileTransactions(c *gin.Context) { var request ReconcileTransactionsRequest err := c.BindJSON(&request) @@ -42,5 +48,8 @@ func (h *Handler) reconcileTransactions(c *gin.Context) { return } - c.JSON(http.StatusOK, SuccessResponse{fmt.Sprintf("Set status for %d transactions", len(request.TransactionIDs))}) + c.JSON(http.StatusOK, ReconcileTransactionsResponse{ + Message: fmt.Sprintf("Set status for %d transactions", len(request.TransactionIDs)), + ReconcilationTransaction: nil, + }) } diff --git a/web/src/pages/Account.vue b/web/src/pages/Account.vue index 6f24f94..a54d4d5 100644 --- a/web/src/pages/Account.vue +++ b/web/src/pages/Account.vue @@ -26,12 +26,14 @@ function cancelReconcilation() { } function submitReconcilation() { - accounts.SubmitReconcilation(); + accounts.SubmitReconcilation(0); accounts.Reconciling = false; } function createReconcilationTransaction() { - + const diff = accounts.ReconcilingBalance - TargetReconcilingBalance.value; + accounts.SubmitReconcilation(diff); + accounts.Reconciling = false; }