feat(expense): import expense

This commit is contained in:
2021-11-30 01:46:51 +01:00
parent 53b0b8c9a2
commit cc6aa27d5d
5 changed files with 112 additions and 6 deletions

View File

@@ -1,8 +1,10 @@
package expense
import (
"github.com/lib/pq"
"nos-comptes/internal/storage/dao/postgresql"
"nos-comptes/internal/utils"
"github.com/lib/pq"
)
type Database struct {
@@ -14,13 +16,16 @@ func (db *Database) CreateExpense(expense *Expense) error {
INSERT INTO public.expense
(account_id, value, type_expense, expense_date, libelle)
VALUES
($1, $2, $3, $4)
($1, $2, $3, $4, $5)
RETURNING id, created_at
`
err := db.Session.
QueryRow(q, expense.AccountId, expense.Value, expense.TypeExpense, expense.ExpenseDate, expense.Libelle).
Scan(&expense.ID, &expense.CreatedAt)
if err != nil {
utils.GetLogger().Info(err)
}
if errPq, ok := err.(*pq.Error); ok {
return postgresql.HandlePgError(errPq)
}