From 95e85aa01197976d0f5b0ecfc3945706c875c3cc Mon Sep 17 00:00:00 2001 From: Derek McQuay Date: Sat, 4 Feb 2017 22:33:01 -0800 Subject: [PATCH] updated category and tranx types they now fit what is in the psql db --- category.go | 43 +------------------------------------------ tranx.go | 10 ++++++---- 2 files changed, 7 insertions(+), 46 deletions(-) diff --git a/category.go b/category.go index 176ebe6..0451836 100644 --- a/category.go +++ b/category.go @@ -1,48 +1,7 @@ package chipmunk -import ( - "fmt" - "time" -) - type category struct { + ID int `json:"id"` Name string `json:"name"` Budget float64 `json:"budget"` - Month month `json:"month"` -} - -type month struct { - M time.Month `json:"m"` - Txs []tranx `json:"txs"` -} - -func getCategory(e string) (int, error) { - for i, c := range categories { - if e == c.Name { - return i, nil - } - } - return 0, fmt.Errorf("could not find category") -} - -//addUser adds user to slice of users -func addCategory(c category) { - _, err := getCategory(c.Name) - if err != nil { - categories = append( - categories, - category{ - Name: c.Name, - Budget: c.Budget, - }, - ) - } -} - -func sumMonth(m month) float64 { - sum := 0.0 - for _, t := range m.Txs { - sum += t.Cost - } - return sum } diff --git a/tranx.go b/tranx.go index 4abfd7b..86fae40 100644 --- a/tranx.go +++ b/tranx.go @@ -3,8 +3,10 @@ package chipmunk import "time" type tranx struct { - Cost float64 `json:"cost"` - Store string `json:"store"` - Info string `json:"Info"` - Month time.Month `json:"Month"` + Cost float64 `json:"cost"` + Store string `json:"store"` + Info string `json:"info"` + Month time.Month `json:"month"` + User_ID int `json:"user_id"` + Category_ID int `json:"category_id"` }