Skip to content

Commit

Permalink
No Account Id Case, interactive buttons and constants (#12)
Browse files Browse the repository at this point in the history
* splitting concerns into separate methods as code-gen doesn't implement an interface

* abstracting out constants and buttons that take you places

* adding functions

* removing swap file
  • Loading branch information
ESteanes authored Sep 11, 2024
1 parent fedcccb commit 78ea371
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 25 deletions.
6 changes: 6 additions & 0 deletions datafetcher/functions/functions.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package functions

const (
AccountIdQueryParam = "accountId"
TransactionNumQueryParam = "numTransaction"
)
5 changes: 3 additions & 2 deletions datafetcher/handlers/transactions.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"strconv"

"github.com/a-h/templ"
"github.com/esteanes/expense-manager/datafetcher/functions"
"github.com/esteanes/expense-manager/datafetcher/templates"
"github.com/esteanes/expense-manager/datafetcher/upclient"
)
Expand All @@ -35,12 +36,12 @@ func NewTransactionHandler(log *log.Logger, upclient *upclient.APIClient, auth c
func (h *TransactionsHandler) Post(w http.ResponseWriter, r *http.Request) {}
func (h *TransactionsHandler) Get(w http.ResponseWriter, r *http.Request) {
queryParams := r.URL.Query()
numTransactions, err := strconv.ParseInt(queryParams.Get("numTransactions"), 10, 32)
numTransactions, err := strconv.ParseInt(queryParams.Get(functions.TransactionNumQueryParam), 10, 32)
if err != nil {
numTransactions = int64(10)
}
transactionsChannel := make(chan upclient.TransactionResource, numTransactions)
accountId := queryParams.Get("accountId")
accountId := queryParams.Get(functions.AccountIdQueryParam)
if accountId == "" {
go h.getTransactionsForAllAccounts(transactionsChannel, int32(numTransactions))
} else {
Expand Down
5 changes: 5 additions & 0 deletions datafetcher/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,11 @@ type GlobalState struct {
Count int
}

const (
AccountIdQueryParam = "accountId"
TransactionNumQueryParam = "numTransaction"
)

var global GlobalState
var sessionManager *scs.SessionManager

Expand Down
8 changes: 7 additions & 1 deletion datafetcher/templates/accounts.templ
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package templates

import (
"github.com/esteanes/expense-manager/datafetcher/functions"
"github.com/esteanes/expense-manager/datafetcher/upclient"
"strings"
)
Expand All @@ -26,9 +27,14 @@ templ AccountDetails(accounts <-chan upclient.AccountResource) {
templ AccountButtons(accounts <-chan upclient.AccountResource) {
<h1>Accounts</h1>
<ul>
<form action="/transactions" method="GET">
<button type="submit">All accounts</button>
</form>
for account := range accounts {
@templ.Flush() {
<button value={ account.Id }>{ account.Attributes.DisplayName } { account.Attributes.Balance.Value } { account.Attributes.Balance.CurrencyCode }</button>
<form action="/transactions" method="GET">
<button type="submit" name={ functions.AccountIdQueryParam } value={ account.Id }>{ account.Attributes.DisplayName } { account.Attributes.Balance.Value } { account.Attributes.Balance.CurrencyCode }</button>
</form>
}
}
</ul>
Expand Down
58 changes: 36 additions & 22 deletions datafetcher/templates/accounts_templ.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 78ea371

Please sign in to comment.