Finalize account view
This commit is contained in:
@ -46,28 +46,41 @@ func (q *Queries) CreateTransaction(ctx context.Context, arg CreateTransactionPa
|
||||
}
|
||||
|
||||
const getTransactionsForAccount = `-- name: GetTransactionsForAccount :many
|
||||
SELECT transactions.id, transactions.date, transactions.memo, transactions.amount, transactions.account_id, transactions.payee_id FROM transactions
|
||||
SELECT transactions.id, transactions.date, transactions.memo, transactions.amount,
|
||||
accounts.name as account, payees.name as payee
|
||||
FROM transactions
|
||||
INNER JOIN accounts ON accounts.id = transactions.account_id
|
||||
INNER JOIN payees ON payees.id = transactions.payee_id
|
||||
WHERE transactions.account_id = $1
|
||||
ORDER BY transactions.date DESC
|
||||
LIMIT 200
|
||||
`
|
||||
|
||||
func (q *Queries) GetTransactionsForAccount(ctx context.Context, accountID uuid.UUID) ([]Transaction, error) {
|
||||
type GetTransactionsForAccountRow struct {
|
||||
ID uuid.UUID
|
||||
Date time.Time
|
||||
Memo string
|
||||
Amount postgres.Numeric
|
||||
Account string
|
||||
Payee string
|
||||
}
|
||||
|
||||
func (q *Queries) GetTransactionsForAccount(ctx context.Context, accountID uuid.UUID) ([]GetTransactionsForAccountRow, error) {
|
||||
rows, err := q.db.QueryContext(ctx, getTransactionsForAccount, accountID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
var items []Transaction
|
||||
var items []GetTransactionsForAccountRow
|
||||
for rows.Next() {
|
||||
var i Transaction
|
||||
var i GetTransactionsForAccountRow
|
||||
if err := rows.Scan(
|
||||
&i.ID,
|
||||
&i.Date,
|
||||
&i.Memo,
|
||||
&i.Amount,
|
||||
&i.AccountID,
|
||||
&i.PayeeID,
|
||||
&i.Account,
|
||||
&i.Payee,
|
||||
); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
Reference in New Issue
Block a user