updated category and tranx types
they now fit what is in the psql db
This commit is contained in:
parent
4ff3ed9112
commit
95e85aa011
43
category.go
43
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
|
||||
}
|
||||
|
6
tranx.go
6
tranx.go
@ -5,6 +5,8 @@ import "time"
|
||||
type tranx struct {
|
||||
Cost float64 `json:"cost"`
|
||||
Store string `json:"store"`
|
||||
Info string `json:"Info"`
|
||||
Month time.Month `json:"Month"`
|
||||
Info string `json:"info"`
|
||||
Month time.Month `json:"month"`
|
||||
User_ID int `json:"user_id"`
|
||||
Category_ID int `json:"category_id"`
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user