コード例 #1
0
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)
}
コード例 #2
0
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)
}
コード例 #3
0
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)
}