feat(expense): import expense
This commit is contained in:
@@ -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)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user