updated category and tranx types

they now fit what is in the psql db
This commit is contained in:
Derek McQuay 2017-02-04 22:33:01 -08:00
parent 4ff3ed9112
commit 95e85aa011
No known key found for this signature in database
GPG Key ID: 92A7BC0C86B0B91A
2 changed files with 7 additions and 46 deletions

View File

@ -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
}

View File

@ -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"`
}