func TestListExpenses(t *testing.T) { tx := dbtest.BeginTx() defer tx.Rollback() _, err := fabricate.Expense(tx).Description("Important Expense").Exec() assert.MustBeNil(t, err) expenses, err := service.ListExpenses(logger.Discard, tx) assert.MustBeNil(t, err) assert.MustBeEqual(t, 1, len(expenses)) assert.Equal(t, "Important Expense", expenses[0].Description) }
func ListExpenses(rw http.ResponseWriter, r *http.Request, c *ctx.Context) error { con, err := c.TxManager.Begin() if err != nil { return err } expenses, err := service.ListExpenses(c.Logger, con) if err != nil { return err } rw.WriteHeader(http.StatusOK) return serialize.ExpensesList(rw, expenses) }
func ListExpenses(rw http.ResponseWriter, r *http.Request, c *ctx.Context) error { tx, err := c.TxManager.Begin() if err != nil { return err } expenses, err := service.ListExpenses(c.Logger, tx) if err != nil { return err } view := new(views.ExpensesList) for _, exp := range expenses { view.Expenses = append(view.Expenses, &views.ExpensesListItem{ Description: exp.Description, Amount: exp.Amount, }) } return views.RenderWithLayout(rw, view) }