debut ajout compte joint
This commit is contained in:
@@ -32,6 +32,31 @@ func (db *Database) CreateExpense(expense *Expense) error {
|
||||
return err
|
||||
}
|
||||
|
||||
func (db Database) GetExpensesOfAnAccountBetween(id, from, to string) ([]*Expense, error) {
|
||||
q := `
|
||||
SELECT a.id, a.account_id, a.value, a.type_expense, a.expense_date, a.created_at, a.updated_at, a.libelle
|
||||
FROM public.expense a
|
||||
WHERE a.account_id = $1
|
||||
AND a.expense_date BETWEEN $2 and $3
|
||||
`
|
||||
rows, err := db.Session.Query(q, id, from, to)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
|
||||
es := make([]*Expense, 0)
|
||||
for rows.Next() {
|
||||
e := Expense{}
|
||||
err := rows.Scan(&e.ID, &e.AccountId, &e.Value, &e.TypeExpense, &e.ExpenseDate, &e.CreatedAt, &e.UpdatedAt, &e.Libelle)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
es = append(es, &e)
|
||||
}
|
||||
return es, nil
|
||||
}
|
||||
|
||||
func (db Database) GetAllExpensesOfAnAccount(id string) ([]*Expense, error) {
|
||||
q := `
|
||||
SELECT a.id, a.account_id, a.value, a.type_expense, a.expense_date, a.created_at, a.updated_at, a.libelle
|
||||
|
||||
Reference in New Issue
Block a user