Add LastDigits and binding to currency for cards
This commit is contained in:
parent
05b5059477
commit
4522d4450f
13
db/card.go
13
db/card.go
|
@ -10,9 +10,12 @@ import (
|
||||||
type Card struct {
|
type Card struct {
|
||||||
gorm.Model
|
gorm.Model
|
||||||
Name string
|
Name string
|
||||||
|
LastDigits string
|
||||||
Balance uint64
|
Balance uint64
|
||||||
HaveCreditLine bool
|
HaveCreditLine bool
|
||||||
CreditLine uint64
|
CreditLine uint64
|
||||||
|
CurrencyID uint
|
||||||
|
Currency *Currency
|
||||||
UserID uint
|
UserID uint
|
||||||
User *User
|
User *User
|
||||||
}
|
}
|
||||||
|
@ -35,6 +38,7 @@ func (c *Card) SetUserID(id uint) {
|
||||||
var (
|
var (
|
||||||
ERROR_CARD_NAME_EMPTY = errors.New("The 'Name' field for 'Card' cannot be empty")
|
ERROR_CARD_NAME_EMPTY = errors.New("The 'Name' field for 'Card' cannot be empty")
|
||||||
ERROR_CARD_NAME_NOT_UNIQUE = errors.New("The 'Name' field for 'Card' have to be unique for user")
|
ERROR_CARD_NAME_NOT_UNIQUE = errors.New("The 'Name' field for 'Card' have to be unique for user")
|
||||||
|
ERROR_CARD_CANT_FIND_CURR = errors.New("The 'CurrencyID' field for 'Card' is invalid")
|
||||||
)
|
)
|
||||||
|
|
||||||
func (c *Card) BeforeSave(tx *gorm.DB) error {
|
func (c *Card) BeforeSave(tx *gorm.DB) error {
|
||||||
|
@ -50,6 +54,15 @@ func (c *Card) BeforeSave(tx *gorm.DB) error {
|
||||||
if c.ID != dup.ID && dup.ID != 0 {
|
if c.ID != dup.ID && dup.ID != 0 {
|
||||||
return ERROR_CARD_NAME_NOT_UNIQUE
|
return ERROR_CARD_NAME_NOT_UNIQUE
|
||||||
}
|
}
|
||||||
|
if c.CurrencyID != 0 {
|
||||||
|
var currency Currency
|
||||||
|
if err := tx.Find(¤cy, c.CurrencyID).Error; err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if currency.ID == 0 {
|
||||||
|
return ERROR_CARD_CANT_FIND_CURR
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user