switched to gorm..

This commit is contained in:
$(pass /github/name)
2024-07-10 14:22:56 +02:00
parent 87e9f71ceb
commit 6ac5491053
27 changed files with 368 additions and 283 deletions

View File

@@ -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
}