switched to gorm..
This commit is contained in:
@@ -2,8 +2,7 @@ package repositories
|
||||
|
||||
import (
|
||||
"GoMembership/internal/models"
|
||||
// "GoMembership/pkg/errors"
|
||||
"database/sql"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
type BankAccountRepository interface {
|
||||
@@ -11,25 +10,17 @@ type BankAccountRepository interface {
|
||||
}
|
||||
|
||||
type bankAccountRepository struct {
|
||||
db *sql.DB
|
||||
db *gorm.DB
|
||||
}
|
||||
|
||||
func NewBankAccountRepository(db *sql.DB) BankAccountRepository {
|
||||
func NewBankAccountRepository(db *gorm.DB) BankAccountRepository {
|
||||
return &bankAccountRepository{db}
|
||||
}
|
||||
|
||||
func (repo *bankAccountRepository) CreateBankAccount(account *models.BankAccount) (int64, error) {
|
||||
|
||||
query := "INSERT INTO banking (user_id, iban, bic, mandate_reference, mandate_date_signed, bank_name, account_holder_name) VALUES (?, ?, ?, ?, ?, ?, ?)"
|
||||
result, err := repo.db.Exec(query, account.UserID, account.IBAN, account.BIC, account.MandateReference, account.MandateDateSigned, account.Bank, account.AccountHolderName)
|
||||
if err != nil {
|
||||
|
||||
return -1, err
|
||||
result := repo.db.Create(account)
|
||||
if result.Error != nil {
|
||||
return 0, result.Error
|
||||
}
|
||||
lastInsertID, err := result.LastInsertId()
|
||||
if err != nil {
|
||||
return -1, err
|
||||
}
|
||||
|
||||
return lastInsertID, err
|
||||
return account.ID, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user