Finalize account view

This commit is contained in:
Jan Bader 2021-12-02 21:49:14 +00:00
parent 871b11bbcc
commit c56335adad
5 changed files with 59 additions and 9 deletions

View File

@ -63,5 +63,5 @@ func (h *Handler) account(c *gin.Context) {
Transactions: transactions,
}
c.HTML(http.StatusOK, "budget.html", d)
c.HTML(http.StatusOK, "account.html", d)
}

View File

@ -52,7 +52,7 @@ func (h *Handler) Serve() {
authenticatedFrontend.GET("/dashboard", h.dashboard)
authenticatedFrontend.GET("/budget/:budgetid", h.budget)
authenticatedFrontend.GET("/budget/:budgetid/accounts", h.accounts)
authenticatedFrontend.GET("/account/:accountid", h.budget)
authenticatedFrontend.GET("/account/:accountid", h.account)
authenticatedFrontend.GET("/admin", h.admin)
authenticatedFrontend.GET("/admin/clear-database", h.clearDatabase)
}

View File

@ -15,7 +15,11 @@ ORDER BY transactions.date DESC
LIMIT 200;
-- name: GetTransactionsForAccount :many
SELECT transactions.* 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;

View File

@ -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
}

33
web/account.html Normal file
View File

@ -0,0 +1,33 @@
{{template "base" .}}
{{define "title"}}{{.Account.Name}}{{end}}
{{define "new"}}
{{template "transaction-new"}}
{{end}}
{{define "main"}}
<div class="budget-item">
<a href="#newtransactionmodal" data-toggle="modal" data-target="#newtransactionmodal">New Transaction</a>
<span class="time"></span>
</div>
<table class="container col-lg-12" id="content">
{{range .Transactions}}
<tr>
<td>{{.Date}}</td>
<td>
{{.Account}}
</td>
<td>
{{.Payee}}
</td>
<td>
<a href="transaction/{{.ID}}">{{.Memo}}</a>
</td>
<td style="text-align: right;{{if .Amount.GetPositive}}{{else}}color: red;{{end}}">
{{printf "%.2f" .Amount.GetFloat64}}
</td>
</tr>
{{end}}
</table>
{{end}}