pushing to github
This commit is contained in:
parent
da62df1bcd
commit
f5d1e2aca3
48
category.go
Normal file
48
category.go
Normal 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
|
||||||
|
}
|
@ -33,6 +33,7 @@ var (
|
|||||||
var Version string = "dev"
|
var Version string = "dev"
|
||||||
var start time.Time
|
var start time.Time
|
||||||
var users []user
|
var users []user
|
||||||
|
var categories []category
|
||||||
|
|
||||||
type failure struct {
|
type failure struct {
|
||||||
Success bool `json:"success"`
|
Success bool `json:"success"`
|
||||||
@ -88,7 +89,7 @@ func (s *Server) tranx(w http.ResponseWriter, r *http.Request) {
|
|||||||
//}
|
//}
|
||||||
switch r.Method {
|
switch r.Method {
|
||||||
default:
|
default:
|
||||||
b, _ := json.Marshal(NewFailure("Allowed method: POST"))
|
b, _ := json.Marshal(NewFailure("Allowed method: POST and GET"))
|
||||||
http.Error(w, string(b), http.StatusBadRequest)
|
http.Error(w, string(b), http.StatusBadRequest)
|
||||||
return
|
return
|
||||||
case "GET":
|
case "GET":
|
||||||
|
2
tranx.go
2
tranx.go
@ -3,7 +3,7 @@ package chipmunk
|
|||||||
import "time"
|
import "time"
|
||||||
|
|
||||||
type tranx struct {
|
type tranx struct {
|
||||||
Cost float32 `json:"cost"`
|
Cost float64 `json:"cost"`
|
||||||
Store string `json:"store"`
|
Store string `json:"store"`
|
||||||
Info string `json:"Info"`
|
Info string `json:"Info"`
|
||||||
Month time.Month `json:"Month"`
|
Month time.Month `json:"Month"`
|
||||||
|
3
user.go
3
user.go
@ -2,12 +2,11 @@ package chipmunk
|
|||||||
|
|
||||||
import "fmt"
|
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 {
|
type user struct {
|
||||||
Info userInfo `json:"info"`
|
Info userInfo `json:"info"`
|
||||||
admin bool `json:"admin"`
|
admin bool `json:"admin"`
|
||||||
txs []tranx `json:"Txs"`
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type userInfo struct {
|
type userInfo struct {
|
||||||
|
Loading…
Reference in New Issue
Block a user