From 6c55e37f20d8ed1240eddbb171a89f10e62bc125 Mon Sep 17 00:00:00 2001 From: Gabe Farrell Date: Sat, 15 Apr 2023 14:05:10 -0400 Subject: [PATCH] Bug Fix: Category case is normalized --- widgets/budget.go | 3 ++- widgets/transactions.go | 7 ++++--- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/widgets/budget.go b/widgets/budget.go index a6cf19a..0204b41 100644 --- a/widgets/budget.go +++ b/widgets/budget.go @@ -6,6 +6,7 @@ import ( "fmt" "net/http" "strconv" + "strings" "github.com/jacobmveber-01839764/BudgetBuddy/db" "github.com/jacobmveber-01839764/BudgetBuddy/money" @@ -94,7 +95,7 @@ func SetCategoryBudget(w http.ResponseWriter, r *http.Request) { // get form values r.ParseForm() - cat := r.FormValue("category") + cat := strings.ToLower(r.FormValue("category")) if cat == "" { w.WriteHeader(http.StatusBadRequest) fmt.Fprintf(w, "{\"error\":\"category must be specified\"}") diff --git a/widgets/transactions.go b/widgets/transactions.go index 02b7846..97d76f0 100644 --- a/widgets/transactions.go +++ b/widgets/transactions.go @@ -6,6 +6,7 @@ import ( "fmt" "net/http" "strconv" + "strings" "time" "github.com/jacobmveber-01839764/BudgetBuddy/db" @@ -113,7 +114,7 @@ func NewTransaction(w http.ResponseWriter, r *http.Request) { if r.FormValue("category") == "" { cat = "uncategorized" } else { - cat = r.FormValue("category") + cat = strings.ToLower(r.FormValue("category")) } newT := db.Transaction{ @@ -129,10 +130,10 @@ func NewTransaction(w http.ResponseWriter, r *http.Request) { var newArr []db.Transaction var success bool - if r.FormValue("type") == "income" { + if strings.ToLower(r.FormValue("type")) == "income" { newArr = append(user.Income, newT) success = addToBalance(user, newT.Amount) - } else if r.FormValue("type") == "expenses" { + } else if strings.ToLower(r.FormValue("type")) == "expenses" { newArr = append(user.Expenses, newT) success = subtractFromBalance(user, newT.Amount) } else {