feat(expense): starting expense handle

This commit is contained in:
2021-11-24 01:07:19 +01:00
parent 917c3a4318
commit 82d86fb33f
4 changed files with 83 additions and 4 deletions

View File

@@ -6,6 +6,30 @@ type Database struct {
*postgresql.DatabasePostgreSQL
}
func (d Database) GetAllExpensesOfAnAccount(id string) (interface{}, interface{}) {
q := `
SELECT a.id, a.user_id, a.name, a.provider, a.created_at, a.updated_at
FROM public.account a
WHERE a.user_id = $1
`
rows, err := db.Session.Query(q, id)
if err != nil {
return nil, err
}
defer rows.Close()
as := make([]*Account, 0)
for rows.Next() {
a := Account{}
err := rows.Scan(&a.ID, &a.UserId, &a.Name, &a.Provider, &a.CreatedAt, &a.UpdatedAt)
if err != nil {
return nil, err
}
as = append(as, &a)
}
return as, nil
}
func NewDatabase(db *postgresql.DatabasePostgreSQL) *Database {
return &Database{db}
}