Skip to content

Commit

Permalink
Tailwind CSS for formatting (#13)
Browse files Browse the repository at this point in the history
* boot-strapped tailwind css

* improved logging

* removing noise
  • Loading branch information
ESteanes authored Sep 12, 2024
1 parent 78ea371 commit b7425a9
Show file tree
Hide file tree
Showing 15 changed files with 737 additions and 60 deletions.
1 change: 1 addition & 0 deletions datafetcher/handlers/accounts.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ func NewAccountHandler(log *log.Logger, upclient *upclient.APIClient, auth conte

func (h *AccountHandler) Post(w http.ResponseWriter, r *http.Request) {}
func (h *AccountHandler) Get(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "text/html charset=utf-8")
filterOwnershipType := upclient.OwnershipTypeEnum("INDIVIDUAL")
accountChannel := make(chan upclient.AccountResource, 10)
clonedChannels := Clone(accountChannel, 2)
Expand Down
2 changes: 1 addition & 1 deletion datafetcher/handlers/basehandler.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ type BaseHandler struct {
}

func (h *BaseHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
h.Log.Println(fmt.Sprintf("%s %s params: %s", r.Method, h.Uri, r.URL.Query()))
h.Log.Println(fmt.Sprintf("%s %s params: %s", r.Method, r.RequestURI, r.URL.Query()))
switch r.Method {
case http.MethodPost:
h.Handler.Post(w, r)
Expand Down
38 changes: 38 additions & 0 deletions datafetcher/handlers/static.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package handlers

import (
"fmt"
"log"
"net/http"
"path/filepath"
)

type StaticFileHandler struct {
*BaseHandler
}

func NewStaticFileHandler(log *log.Logger) *StaticFileHandler {
handler := &StaticFileHandler{}
handler.BaseHandler = &BaseHandler{
Uri: "/static/",
Log: log,
UpClient: nil,
UpAuth: nil,
Handler: handler}
return handler
}
func (s *StaticFileHandler) Get(w http.ResponseWriter, r *http.Request) {
if r.RequestURI != "/static/css/output.css" {
http.Error(w, "Internal Server Error", http.StatusInternalServerError)
return
}
filePath := r.URL.Path[len("/static/"):]
fullPath := filepath.Join(".", "static", filePath)
s.Log.Println(fmt.Sprintf("Attempting to serve path: %s", fullPath))
http.ServeFile(w, r, fullPath)
}

func (s *StaticFileHandler) Post(w http.ResponseWriter, r *http.Request) {
s.Log.Println("Unsupported HTTP Method")
http.Error(w, "Internal Server Error", http.StatusInternalServerError)
}
3 changes: 1 addition & 2 deletions datafetcher/handlers/transactions-csv.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@ func NewTransactionCsvHandler(log *log.Logger, upclient *upclient.APIClient, aut
Log: log,
UpClient: upclient,
UpAuth: auth,
Handler: handler, // Set the Handler interface to the specific handler
}
Handler: handler}
return handler
}

Expand Down
16 changes: 2 additions & 14 deletions datafetcher/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package datafetcher

import (
"context"
"fmt"
"log"
"net/http"
"time"
Expand All @@ -14,12 +13,6 @@ import (
"github.com/alexedwards/scs/v2"
)

// homePage function to handle requests to the root URL
func homePage(w http.ResponseWriter, r *http.Request) {
fmt.Fprintf(w, "Welcome to the HomePage!")
fmt.Println("Endpoint Hit: homePage")
}

func getInfo(w http.ResponseWriter, r *http.Request) {

}
Expand All @@ -40,11 +33,6 @@ type GlobalState struct {
Count int
}

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

var global GlobalState
var sessionManager *scs.SessionManager

Expand Down Expand Up @@ -93,12 +81,12 @@ func HandleRequests(upBankToken string, log *log.Logger) {
accountHandler := handlers.NewAccountHandler(log, apiClient, auth)
transactionsHandler := handlers.NewTransactionHandler(log, apiClient, auth, accountHandler)
transactionsCsvHandler := handlers.NewTransactionCsvHandler(log, apiClient, auth)
staticFileHandler := handlers.NewStaticFileHandler(log)
mux := http.NewServeMux()
mux.HandleFunc(accountHandler.Uri, accountHandler.ServeHTTP)
mux.HandleFunc(transactionsHandler.Uri, transactionsHandler.ServeHTTP)
mux.HandleFunc(transactionsCsvHandler.Uri, transactionsCsvHandler.ServeHTTP)

mux.HandleFunc("/", homePage)
mux.HandleFunc(staticFileHandler.Uri, staticFileHandler.ServeHTTP)
mux.HandleFunc("/info", getInfo)
mux.Handle("/time", NewNowHandler(time.Now))
mux.HandleFunc("/counter", handleInfo)
Expand Down
8 changes: 5 additions & 3 deletions datafetcher/templates/accounts.templ
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ import (
)

templ AccountDetails(accounts <-chan upclient.AccountResource) {
<h1>Accounts</h1>
<h1 class="text-4xl">Accounts - Details</h1>
<ul>
for account := range accounts {
@templ.Flush() {
<div>
<h2>{ account.Attributes.DisplayName }</h2>
<h2 class="text-xl font-bold">{ account.Attributes.DisplayName }</h2>
<p>Account Type: { strings.ToTitle(string(account.Attributes.AccountType)) }</p>
<p>Balance: { account.Attributes.Balance.CurrencyCode } { account.Attributes.Balance.Value }</p>
<p>Created At: { account.Attributes.CreatedAt.String() }</p>
Expand All @@ -25,7 +25,7 @@ templ AccountDetails(accounts <-chan upclient.AccountResource) {
}

templ AccountButtons(accounts <-chan upclient.AccountResource) {
<h1>Accounts</h1>
<h1 class="text-4xl">Accounts</h1>
<ul>
<form action="/transactions" method="GET">
<button type="submit">All accounts</button>
Expand All @@ -46,6 +46,8 @@ templ Accounts(accounts1 <-chan upclient.AccountResource, accounts2 <-chan upcli
<head>
<meta charset="UTF-8"/>
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
<script src="https://unpkg.com/[email protected]"></script>
<link rel="stylesheet" href="/static/css/output.css"/>
<title>Accounts</title>
</head>
<body>
Expand Down
40 changes: 20 additions & 20 deletions datafetcher/templates/accounts_templ.go

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

19 changes: 19 additions & 0 deletions datafetcher/templates/accounts_templ.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<h1 class=\"text-4xl\">Accounts - Details</h1><ul>
<div><h2 class=\"text-xl font-bold\">
</h2><p>Account Type:
</p><p>Balance:

</p><p>Created At:
</p><p>Id:
</p></div><hr>
</ul>
<h1 class=\"text-4xl\">Accounts</h1><ul><form action=\"/transactions\" method=\"GET\"><button type=\"submit\">All accounts</button></form>
<form action=\"/transactions\" method=\"GET\"><button type=\"submit\" name=\"
\" value=\"
\">


</button></form>
</ul>
<!doctype html><html lang=\"en\"><head><meta charset=\"UTF-8\"><meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\"><script src=\"https://unpkg.com/[email protected]\"></script><link rel=\"stylesheet\" href=\"/static/css/output.css\"><title>Accounts</title></head><body>
</body></html>
Loading

0 comments on commit b7425a9

Please sign in to comment.