models

package
v0.0.0-...-bc49644 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 2, 2024 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Hash

func Hash(secret string) ([]byte, error)

func SanitizeAccounts

func SanitizeAccounts(accounts *[]Account)

func SanitizeTransferAccounts

func SanitizeTransferAccounts(transfers *[]Transfer)

func VerifySecret

func VerifySecret(hashedSecret, secret string) error

Types

type Account

type Account struct {
	ID        uint64    `gorm:"primary_key;auto_increment" json:"id"`
	Name      string    `gorm:"size:255;not null;" json:"name"`
	CPF       string    `gorm:"size:11; not null;unique" json:"cpf"`
	Secret    string    `gorm:"size:100;not null;" json:"secret"`
	Balance   float64   `gorm:"default:0; not null" json:"balance"`
	CreatedAt time.Time `gorm:"default:CURRENT_TIMESTAMP" json:"created_at"`
}

func (*Account) BeforeSave

func (a *Account) BeforeSave() error

func (*Account) DepositOnBalance

func (a *Account) DepositOnBalance(db *gorm.DB, amount float64) error

func (*Account) FindAccountBalanceByID

func (a *Account) FindAccountBalanceByID(db *gorm.DB, id uint64) (*Balance, error)

func (*Account) FindAccountByCPF

func (a *Account) FindAccountByCPF(db *gorm.DB, cpf string) (*Account, error)

func (*Account) FindAccountByID

func (a *Account) FindAccountByID(db *gorm.DB, id uint64) (*Account, error)

func (*Account) FindAllAccounts

func (a *Account) FindAllAccounts(db *gorm.DB) (*[]Account, error)

func (*Account) Prepare

func (a *Account) Prepare()

func (*Account) SanitizeAccount

func (a *Account) SanitizeAccount()

func (*Account) SaveAccount

func (a *Account) SaveAccount(db *gorm.DB) (*Account, error)

func (*Account) UpdateBalance

func (a *Account) UpdateBalance(db *gorm.DB, balance float64) error

func (*Account) Validate

func (a *Account) Validate(action string) error

func (*Account) ValidateCPF

func (a *Account) ValidateCPF() error

func (*Account) ValidateName

func (a *Account) ValidateName() error

func (*Account) ValidateSecret

func (a *Account) ValidateSecret() error

func (*Account) ValidateUniqueCPF

func (a *Account) ValidateUniqueCPF(db *gorm.DB) error

func (*Account) WithdrawFromBalance

func (a *Account) WithdrawFromBalance(db *gorm.DB, amount float64) error

type Balance

type Balance struct {
	Balance float64 `json:"account_balance"`
}

type Transfer

type Transfer struct {
	ID                     uint64    `gorm:"primary_key;auto_increment" json:"id"`
	Account_origin_id      uint64    `gorm:"not null" json:"account_origin_id"`
	Account_origin         Account   `gorm:"foreignkey:Account_origin_id"`
	Account_destination_id uint64    `gorm:"not null" json:"account_destination_id"`
	Account_destination    Account   `gorm:"foreignkey:Account_destination_id"`
	Amount                 float64   `gorm:"default:0; not null" json:"amount"`
	CreatedAt              time.Time `gorm:"default:CURRENT_TIMESTAMP" json:"created_at"`
}

func (*Transfer) FindAllTransfersById

func (t *Transfer) FindAllTransfersById(db *gorm.DB, account_id uint64) (*[]Transfer, error)

func (*Transfer) Prepare

func (t *Transfer) Prepare(account_origin_id uint64)

func (*Transfer) SaveTransfer

func (t *Transfer) SaveTransfer(db *gorm.DB) (*Transfer, error)

func (*Transfer) Validate

func (t *Transfer) Validate(db *gorm.DB) error

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL