Implement update and delete for transactions
This commit is contained in:
@ -8,6 +8,20 @@ INSERT INTO transactions
|
||||
VALUES ($1, $2, $3, $4, $5, $6)
|
||||
RETURNING *;
|
||||
|
||||
-- name: UpdateTransaction :exec
|
||||
UPDATE transactions
|
||||
SET date = $1,
|
||||
memo = $2,
|
||||
amount = $3,
|
||||
account_id = $4,
|
||||
payee_id = $5,
|
||||
category_id = $6
|
||||
WHERE id = $7;
|
||||
|
||||
-- name: DeleteTransaction :exec
|
||||
DELETE FROM transactions
|
||||
WHERE id = $1;
|
||||
|
||||
-- name: GetTransactionsForBudget :many
|
||||
SELECT transactions.id, transactions.date, transactions.memo, transactions.amount,
|
||||
accounts.name as account, COALESCE(payees.name, '') as payee, COALESCE(category_groups.name, '') as category_group, COALESCE(categories.name, '') as category
|
||||
|
@ -63,6 +63,16 @@ func (q *Queries) DeleteAllTransactions(ctx context.Context, budgetID uuid.UUID)
|
||||
return result.RowsAffected()
|
||||
}
|
||||
|
||||
const deleteTransaction = `-- name: DeleteTransaction :exec
|
||||
DELETE FROM transactions
|
||||
WHERE id = $1
|
||||
`
|
||||
|
||||
func (q *Queries) DeleteTransaction(ctx context.Context, id uuid.UUID) error {
|
||||
_, err := q.db.ExecContext(ctx, deleteTransaction, id)
|
||||
return err
|
||||
}
|
||||
|
||||
const getTransaction = `-- name: GetTransaction :one
|
||||
SELECT id, date, memo, amount, account_id, category_id, payee_id FROM transactions
|
||||
WHERE id = $1
|
||||
@ -228,3 +238,37 @@ func (q *Queries) GetTransactionsForBudget(ctx context.Context, budgetID uuid.UU
|
||||
}
|
||||
return items, nil
|
||||
}
|
||||
|
||||
const updateTransaction = `-- name: UpdateTransaction :exec
|
||||
UPDATE transactions
|
||||
SET date = $1,
|
||||
memo = $2,
|
||||
amount = $3,
|
||||
account_id = $4,
|
||||
payee_id = $5,
|
||||
category_id = $6
|
||||
WHERE id = $7
|
||||
`
|
||||
|
||||
type UpdateTransactionParams struct {
|
||||
Date time.Time
|
||||
Memo string
|
||||
Amount Numeric
|
||||
AccountID uuid.UUID
|
||||
PayeeID uuid.NullUUID
|
||||
CategoryID uuid.NullUUID
|
||||
ID uuid.UUID
|
||||
}
|
||||
|
||||
func (q *Queries) UpdateTransaction(ctx context.Context, arg UpdateTransactionParams) error {
|
||||
_, err := q.db.ExecContext(ctx, updateTransaction,
|
||||
arg.Date,
|
||||
arg.Memo,
|
||||
arg.Amount,
|
||||
arg.AccountID,
|
||||
arg.PayeeID,
|
||||
arg.CategoryID,
|
||||
arg.ID,
|
||||
)
|
||||
return err
|
||||
}
|
||||
|
Reference in New Issue
Block a user