pushing to github

This commit is contained in:
Derek McQuay 2017-01-20 14:22:01 -08:00
parent da62df1bcd
commit f5d1e2aca3
5 changed files with 72 additions and 70 deletions

48
category.go Normal file
View File

@ -0,0 +1,48 @@
package chipmunk
import (
"fmt"
"time"
)
type category struct {
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

@ -33,6 +33,7 @@ var (
var Version string = "dev"
var start time.Time
var users []user
var categories []category
type failure struct {
Success bool `json:"success"`
@ -88,7 +89,7 @@ func (s *Server) tranx(w http.ResponseWriter, r *http.Request) {
//}
switch r.Method {
default:
b, _ := json.Marshal(NewFailure("Allowed method: POST"))
b, _ := json.Marshal(NewFailure("Allowed method: POST and GET"))
http.Error(w, string(b), http.StatusBadRequest)
return
case "GET":

File diff suppressed because one or more lines are too long

View File

@ -3,7 +3,7 @@ package chipmunk
import "time"
type tranx struct {
Cost float32 `json:"cost"`
Cost float64 `json:"cost"`
Store string `json:"store"`
Info string `json:"Info"`
Month time.Month `json:"Month"`

View File

@ -2,12 +2,11 @@ package chipmunk
import "fmt"
var authEmails []string = []string{"derekmcquay@gmail.com", "colleenmmcquay@gmail.com", "dmmllnl@gmail.com"}
var authEmails []string = []string{"derekmcquay@gmail.com", "colleenmmcquay@gmail.com"}
type user struct {
Info userInfo `json:"info"`
admin bool `json:"admin"`
txs []tranx `json:"Txs"`
}
type userInfo struct {