Calorie counting web application written in the Go language

home.go 792B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. package controllers
  2. import (
  3. "github.com/revel/revel"
  4. "github.com/revolvingcow/grassfed/app/models"
  5. )
  6. type Home struct {
  7. Application
  8. }
  9. func (c Home) getNumberOfAccounts() (count int64) {
  10. count, err := c.Transaction.SelectInt(`select count(*) from Account`)
  11. if err != nil {
  12. return 0
  13. }
  14. return count
  15. }
  16. func (c Home) getNumberOfCalories() (calories int64) {
  17. calories, err := c.Transaction.SelectInt(`select sum(Calories) from History`)
  18. if err != nil {
  19. return 0
  20. }
  21. return calories
  22. }
  23. func (c Home) Index() revel.Result {
  24. return c.Render()
  25. }
  26. func (c Home) About() revel.Result {
  27. return c.Render()
  28. }
  29. func (c Home) Overview() revel.Result {
  30. model := models.Overview{
  31. Accounts: c.getNumberOfAccounts(),
  32. Calories: c.getNumberOfCalories(),
  33. }
  34. return c.RenderJson(model)
  35. }