debut ajout compte joint

This commit is contained in:
2022-05-13 01:38:03 +02:00
parent cc6aa27d5d
commit 19a642b4d4
14 changed files with 785 additions and 1 deletions

View File

@@ -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