36 lines
764 B
Go
36 lines
764 B
Go
package expense
|
|
|
|
import "nos-comptes/internal/storage/dao/postgresql"
|
|
|
|
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}
|
|
}
|