From 6cafaec42261d29bdce5d59622c07b54d8d2f151 Mon Sep 17 00:00:00 2001 From: Jan Bader Date: Wed, 9 Feb 2022 21:55:36 +0000 Subject: [PATCH 1/9] Inline tv and bv vars --- cmd/budgeteer/main.go | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/cmd/budgeteer/main.go b/cmd/budgeteer/main.go index a6d6f58..9ce1ef2 100644 --- a/cmd/budgeteer/main.go +++ b/cmd/budgeteer/main.go @@ -16,19 +16,16 @@ func main() { log.Fatalf("Could not load config: %v", err) } - bv := &bcrypt.Verifier{} - - q, err := postgres.Connect(cfg.DatabaseHost, cfg.DatabaseUser, cfg.DatabasePassword, cfg.DatabaseName) + q, err := postgres.Connect(cfg.DatabaseConnection) if err != nil { log.Fatalf("Failed connecting to DB: %v", err) } - tv := &jwt.TokenVerifier{} - h := &http.Handler{ Service: q, - TokenVerifier: tv, - CredentialsVerifier: bv, + TokenVerifier: &jwt.TokenVerifier{}, + CredentialsVerifier: &bcrypt.Verifier{}, } + h.Serve() } From 922041856f4c72fc008702c777d5ba5d28f7732b Mon Sep 17 00:00:00 2001 From: Jan Bader Date: Wed, 9 Feb 2022 21:56:00 +0000 Subject: [PATCH 2/9] Extract struct for return value of getTransactionsForAccount --- http/account.go | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/http/account.go b/http/account.go index 93867a7..03296c2 100644 --- a/http/account.go +++ b/http/account.go @@ -28,8 +28,10 @@ func (h *Handler) transactionsForAccount(c *gin.Context) { return } - c.JSON(http.StatusOK, struct { - Account postgres.Account - Transactions []postgres.GetTransactionsForAccountRow - }{account, transactions}) + c.JSON(http.StatusOK, TransactionsResponse{account, transactions}) +} + +type TransactionsResponse struct { + Account postgres.Account + Transactions []postgres.GetTransactionsForAccountRow } From c3a1564c4eb043a18c32f1e8d8ec1ed0a383a60f Mon Sep 17 00:00:00 2001 From: Jan Bader Date: Wed, 9 Feb 2022 21:56:40 +0000 Subject: [PATCH 3/9] Extract LoadRoutes method --- http/http.go | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/http/http.go b/http/http.go index 745e60b..53870b4 100644 --- a/http/http.go +++ b/http/http.go @@ -4,7 +4,6 @@ import ( "io/fs" "net/http" "strings" - "time" "git.javil.eu/jacob1123/budgeteer" "git.javil.eu/jacob1123/budgeteer/bcrypt" @@ -25,11 +24,15 @@ const ( expiration = 72 ) -// Serve starts the HTTP Server +// Serve starts the http server func (h *Handler) Serve() { router := gin.Default() - router.FuncMap["now"] = time.Now + h.LoadRoutes(router) + router.Run(":1323") +} +// LoadRoutes initializes all the routes +func (h *Handler) LoadRoutes(router *gin.Engine) { static, err := fs.Sub(web.Static, "dist") if err != nil { panic("couldn't open static files") @@ -77,8 +80,6 @@ func (h *Handler) Serve() { transaction := authenticated.Group("/transaction") transaction.POST("/new", h.newTransaction) transaction.POST("/:transactionid", h.newTransaction) - - router.Run(":1323") } func enableCachingForStaticFiles() gin.HandlerFunc { From 3bd584506851c307e61a8aa2902b6057a70cd81e Mon Sep 17 00:00:00 2001 From: Jan Bader Date: Wed, 9 Feb 2022 21:56:59 +0000 Subject: [PATCH 4/9] Focus next element on Enter --- web/src/components/Autocomplete.vue | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/web/src/components/Autocomplete.vue b/web/src/components/Autocomplete.vue index e524dfb..4ce4fa9 100644 --- a/web/src/components/Autocomplete.vue +++ b/web/src/components/Autocomplete.vue @@ -56,6 +56,12 @@ export default defineComponent({ if(e.key == "Enter") { const selected = this.$data.Suggestions[0]; this.selectElement(selected); + const el = (e.target); + const inputElements = Array.from(el.ownerDocument.querySelectorAll('input:not([disabled]):not([readonly])')); + const currentIndex = inputElements.indexOf(el); + const nextElement = inputElements[currentIndex < inputElements.length - 1 ? currentIndex + 1 : 0]; + (nextElement).focus(); + } }, selectElement(element : Suggestion) { From 2c71c521f9e6ad3aae3dcf267d6b7570de477975 Mon Sep 17 00:00:00 2001 From: Jan Bader Date: Wed, 9 Feb 2022 21:57:25 +0000 Subject: [PATCH 5/9] Add bordersr to inputs --- web/src/components/Autocomplete.vue | 2 +- web/src/pages/Account.vue | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/web/src/components/Autocomplete.vue b/web/src/components/Autocomplete.vue index 4ce4fa9..e4e14ba 100644 --- a/web/src/components/Autocomplete.vue +++ b/web/src/components/Autocomplete.vue @@ -88,7 +88,7 @@ export default defineComponent({