mirror of
https://github.com/gabehf/BudgetBuddy.git
synced 2026-03-16 10:46:01 -07:00
Bug Fix: Category case is normalized
This commit is contained in:
parent
8cbb8ee963
commit
6c55e37f20
2 changed files with 6 additions and 4 deletions
|
|
@ -6,6 +6,7 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"net/http"
|
"net/http"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
"strings"
|
||||||
|
|
||||||
"github.com/jacobmveber-01839764/BudgetBuddy/db"
|
"github.com/jacobmveber-01839764/BudgetBuddy/db"
|
||||||
"github.com/jacobmveber-01839764/BudgetBuddy/money"
|
"github.com/jacobmveber-01839764/BudgetBuddy/money"
|
||||||
|
|
@ -94,7 +95,7 @@ func SetCategoryBudget(w http.ResponseWriter, r *http.Request) {
|
||||||
|
|
||||||
// get form values
|
// get form values
|
||||||
r.ParseForm()
|
r.ParseForm()
|
||||||
cat := r.FormValue("category")
|
cat := strings.ToLower(r.FormValue("category"))
|
||||||
if cat == "" {
|
if cat == "" {
|
||||||
w.WriteHeader(http.StatusBadRequest)
|
w.WriteHeader(http.StatusBadRequest)
|
||||||
fmt.Fprintf(w, "{\"error\":\"category must be specified\"}")
|
fmt.Fprintf(w, "{\"error\":\"category must be specified\"}")
|
||||||
|
|
|
||||||
|
|
@ -6,6 +6,7 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"net/http"
|
"net/http"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/jacobmveber-01839764/BudgetBuddy/db"
|
"github.com/jacobmveber-01839764/BudgetBuddy/db"
|
||||||
|
|
@ -113,7 +114,7 @@ func NewTransaction(w http.ResponseWriter, r *http.Request) {
|
||||||
if r.FormValue("category") == "" {
|
if r.FormValue("category") == "" {
|
||||||
cat = "uncategorized"
|
cat = "uncategorized"
|
||||||
} else {
|
} else {
|
||||||
cat = r.FormValue("category")
|
cat = strings.ToLower(r.FormValue("category"))
|
||||||
}
|
}
|
||||||
|
|
||||||
newT := db.Transaction{
|
newT := db.Transaction{
|
||||||
|
|
@ -129,10 +130,10 @@ func NewTransaction(w http.ResponseWriter, r *http.Request) {
|
||||||
|
|
||||||
var newArr []db.Transaction
|
var newArr []db.Transaction
|
||||||
var success bool
|
var success bool
|
||||||
if r.FormValue("type") == "income" {
|
if strings.ToLower(r.FormValue("type")) == "income" {
|
||||||
newArr = append(user.Income, newT)
|
newArr = append(user.Income, newT)
|
||||||
success = addToBalance(user, newT.Amount)
|
success = addToBalance(user, newT.Amount)
|
||||||
} else if r.FormValue("type") == "expenses" {
|
} else if strings.ToLower(r.FormValue("type")) == "expenses" {
|
||||||
newArr = append(user.Expenses, newT)
|
newArr = append(user.Expenses, newT)
|
||||||
success = subtractFromBalance(user, newT.Amount)
|
success = subtractFromBalance(user, newT.Amount)
|
||||||
} else {
|
} else {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue