refactoring
This commit is contained in:
@@ -1,15 +1,50 @@
|
||||
package models
|
||||
|
||||
import "time"
|
||||
import (
|
||||
"GoMembership/pkg/logger"
|
||||
"time"
|
||||
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
type BankAccount struct {
|
||||
ID uint `gorm:"primaryKey"`
|
||||
CreatedAt time.Time
|
||||
UpdatedAt time.Time
|
||||
MandateDateSigned time.Time `gorm:"not null" json:"mandate_date_signed"`
|
||||
UserID uint `gorm:"index" json:"user_id"`
|
||||
MandateDateSigned time.Time `json:"mandate_date_signed"`
|
||||
Bank string `json:"bank_name" binding:"safe_content"`
|
||||
AccountHolderName string `json:"account_holder_name" binding:"safe_content"`
|
||||
IBAN string `json:"iban" binding:"safe_content"`
|
||||
BIC string `json:"bic" binding:"safe_content"`
|
||||
MandateReference string `gorm:"not null" json:"mandate_reference" binding:"safe_content"`
|
||||
MandateReference string `json:"mandate_reference" binding:"safe_content"`
|
||||
}
|
||||
|
||||
func (b *BankAccount) Create(db *gorm.DB) error {
|
||||
// b.ID = 0
|
||||
// only the children the belongs to association gets a reference id
|
||||
if err := db.Create(b).Error; err != nil {
|
||||
return err
|
||||
}
|
||||
logger.Info.Printf("BankAccount created: %#v", b)
|
||||
return db.First(b, b.ID).Error // Refresh the object with all associations
|
||||
|
||||
}
|
||||
|
||||
func (b *BankAccount) Update(db *gorm.DB) error {
|
||||
var existingBankAccount BankAccount
|
||||
|
||||
logger.Info.Printf("updating BankAccount: %#v", b)
|
||||
if err := db.First(&existingBankAccount, b.ID).Error; err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if err := db.Model(&existingBankAccount).Updates(b).Error; err != nil {
|
||||
return err
|
||||
}
|
||||
return db.First(b, b.ID).Error
|
||||
}
|
||||
|
||||
func (b *BankAccount) Delete(db *gorm.DB) error {
|
||||
return db.Delete(&b).Error
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user