diff --git a/datafetcher/functions/functions.go b/datafetcher/functions/functions.go new file mode 100644 index 0000000..25edad4 --- /dev/null +++ b/datafetcher/functions/functions.go @@ -0,0 +1,6 @@ +package functions + +const ( + AccountIdQueryParam = "accountId" + TransactionNumQueryParam = "numTransaction" +) diff --git a/datafetcher/handlers/transactions.go b/datafetcher/handlers/transactions.go index 7fbbb1e..8014af6 100644 --- a/datafetcher/handlers/transactions.go +++ b/datafetcher/handlers/transactions.go @@ -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" ) @@ -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 { diff --git a/datafetcher/server.go b/datafetcher/server.go index 80457ac..40523ed 100644 --- a/datafetcher/server.go +++ b/datafetcher/server.go @@ -40,6 +40,11 @@ type GlobalState struct { Count int } +const ( + AccountIdQueryParam = "accountId" + TransactionNumQueryParam = "numTransaction" +) + var global GlobalState var sessionManager *scs.SessionManager diff --git a/datafetcher/templates/accounts.templ b/datafetcher/templates/accounts.templ index 4bb44ee..935de99 100644 --- a/datafetcher/templates/accounts.templ +++ b/datafetcher/templates/accounts.templ @@ -1,6 +1,7 @@ package templates import ( + "github.com/esteanes/expense-manager/datafetcher/functions" "github.com/esteanes/expense-manager/datafetcher/upclient" "strings" ) @@ -26,9 +27,14 @@ templ AccountDetails(accounts <-chan upclient.AccountResource) { templ AccountButtons(accounts <-chan upclient.AccountResource) {

Accounts

diff --git a/datafetcher/templates/accounts_templ.go b/datafetcher/templates/accounts_templ.go index 9d0eb77..83c6b31 100644 --- a/datafetcher/templates/accounts_templ.go +++ b/datafetcher/templates/accounts_templ.go @@ -9,6 +9,7 @@ import "github.com/a-h/templ" import templruntime "github.com/a-h/templ/runtime" import ( + "github.com/esteanes/expense-manager/datafetcher/functions" "github.com/esteanes/expense-manager/datafetcher/upclient" "strings" ) @@ -55,7 +56,7 @@ func AccountDetails(accounts <-chan upclient.AccountResource) templ.Component { var templ_7745c5c3_Var3 string templ_7745c5c3_Var3, templ_7745c5c3_Err = templ.JoinStringErrs(account.Attributes.DisplayName) if templ_7745c5c3_Err != nil { - return templ.Error{Err: templ_7745c5c3_Err, FileName: `datafetcher/templates/accounts.templ`, Line: 14, Col: 41} + return templ.Error{Err: templ_7745c5c3_Err, FileName: `datafetcher/templates/accounts.templ`, Line: 15, Col: 41} } _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var3)) if templ_7745c5c3_Err != nil { @@ -68,7 +69,7 @@ func AccountDetails(accounts <-chan upclient.AccountResource) templ.Component { var templ_7745c5c3_Var4 string templ_7745c5c3_Var4, templ_7745c5c3_Err = templ.JoinStringErrs(strings.ToTitle(string(account.Attributes.AccountType))) if templ_7745c5c3_Err != nil { - return templ.Error{Err: templ_7745c5c3_Err, FileName: `datafetcher/templates/accounts.templ`, Line: 15, Col: 79} + return templ.Error{Err: templ_7745c5c3_Err, FileName: `datafetcher/templates/accounts.templ`, Line: 16, Col: 79} } _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var4)) if templ_7745c5c3_Err != nil { @@ -81,7 +82,7 @@ func AccountDetails(accounts <-chan upclient.AccountResource) templ.Component { var templ_7745c5c3_Var5 string templ_7745c5c3_Var5, templ_7745c5c3_Err = templ.JoinStringErrs(account.Attributes.Balance.CurrencyCode) if templ_7745c5c3_Err != nil { - return templ.Error{Err: templ_7745c5c3_Err, FileName: `datafetcher/templates/accounts.templ`, Line: 16, Col: 58} + return templ.Error{Err: templ_7745c5c3_Err, FileName: `datafetcher/templates/accounts.templ`, Line: 17, Col: 58} } _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var5)) if templ_7745c5c3_Err != nil { @@ -94,7 +95,7 @@ func AccountDetails(accounts <-chan upclient.AccountResource) templ.Component { var templ_7745c5c3_Var6 string templ_7745c5c3_Var6, templ_7745c5c3_Err = templ.JoinStringErrs(account.Attributes.Balance.Value) if templ_7745c5c3_Err != nil { - return templ.Error{Err: templ_7745c5c3_Err, FileName: `datafetcher/templates/accounts.templ`, Line: 16, Col: 95} + return templ.Error{Err: templ_7745c5c3_Err, FileName: `datafetcher/templates/accounts.templ`, Line: 17, Col: 95} } _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var6)) if templ_7745c5c3_Err != nil { @@ -107,7 +108,7 @@ func AccountDetails(accounts <-chan upclient.AccountResource) templ.Component { var templ_7745c5c3_Var7 string templ_7745c5c3_Var7, templ_7745c5c3_Err = templ.JoinStringErrs(account.Attributes.CreatedAt.String()) if templ_7745c5c3_Err != nil { - return templ.Error{Err: templ_7745c5c3_Err, FileName: `datafetcher/templates/accounts.templ`, Line: 17, Col: 59} + return templ.Error{Err: templ_7745c5c3_Err, FileName: `datafetcher/templates/accounts.templ`, Line: 18, Col: 59} } _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var7)) if templ_7745c5c3_Err != nil { @@ -120,7 +121,7 @@ func AccountDetails(accounts <-chan upclient.AccountResource) templ.Component { var templ_7745c5c3_Var8 string templ_7745c5c3_Var8, templ_7745c5c3_Err = templ.JoinStringErrs(account.Id) if templ_7745c5c3_Err != nil { - return templ.Error{Err: templ_7745c5c3_Err, FileName: `datafetcher/templates/accounts.templ`, Line: 18, Col: 24} + return templ.Error{Err: templ_7745c5c3_Err, FileName: `datafetcher/templates/accounts.templ`, Line: 19, Col: 24} } _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var8)) if templ_7745c5c3_Err != nil { @@ -163,7 +164,7 @@ func AccountButtons(accounts <-chan upclient.AccountResource) templ.Component { templ_7745c5c3_Var9 = templ.NopComponent } ctx = templ.ClearChildren(ctx) - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("

Accounts