model

package
v0.0.1-118 Latest Latest
Warning

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

Go to latest
Published: Apr 16, 2020 License: MIT Imports: 4 Imported by: 11

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrAccountStatusInvalid = errors.New("Invalid AccountStatus")
)
View Source
var (
	ErrOperationTypeInvalid = errors.New("Invalid OperationType")
)
View Source
var (
	ErrSynchroneousTypeInvalid = errors.New("Invalid SynchroneousType")
)

Functions

This section is empty.

Types

type Account added in v0.0.2

type Account struct {
	ID           AccountID    `gorm:"primary_key"`                     // [PK] Account
	UserID       UserID       `gorm:"index;not null"`                  // [FK] Reference to User table
	CurrencyName CurrencyName `gorm:"index;not null;type:varchar(16)"` // [FK] Reference to Currency table
	Name         AccountName  `gorm:"index;not null"`                  // [U] Unique Account name for User and Currency
}

type AccountID added in v0.0.2

type AccountID ID

type AccountName added in v0.0.2

type AccountName String

type AccountOperation added in v0.0.2

type AccountOperation struct {
	ID        AccountOperationID `gorm:"primary_key;unique_index:idx_id_previd;"` // [PK] AccountOperation
	PrevID    AccountOperationID `gorm:"unique_index:idx_id_previd;not null"`     // [FK] Reference to previous AccountOperation (0 mean first operation)
	AccountID AccountID          `gorm:"index;not null"`                          // [FK] Reference to Account table

	SynchroneousType SynchroneousType `gorm:"index;not null;type:varchar(16)"` // [enum] Operation synchroneous type (sync, async-start, async-end)
	OperationType    OperationType    `gorm:"index;not null;type:varchar(16)"` // [enum] Determine table for ReferenceID (deposit, withdraw, transfert, adjustment, none, other)
	ReferenceID      RefID            `gorm:"index;not null"`                  // [optional - FK] Reference to related table with OperationType

	Timestamp time.Time `gorm:"index;not null;type:timestamp"` // Operation timestamp
	Amount    ZeroFloat `gorm:"default:0;not null"`            // Operation amount (can be negative)
	Balance   ZeroFloat `gorm:"default:0;not null"`            // Account balance (strictly positive or zero)

	LockAmount  ZeroFloat `gorm:"default:0;not null"` // Operation amount (can be negative)
	TotalLocked ZeroFloat `gorm:"default:0;not null"` // Total locked (strictly positive or zero and less or equal than Balance)
}

AccountOperation model

func NewAccountOperation added in v0.0.2

func NewAccountOperation(ID, prevID AccountOperationID, accountID AccountID, synchroneousType SynchroneousType, operationType OperationType, referenceID RefID, timestamp time.Time, amount, balance, lockAmount, totalLocked Float) AccountOperation

func (*AccountOperation) IsValid added in v0.0.2

func (p *AccountOperation) IsValid() bool

func (*AccountOperation) PreCheck added in v0.0.2

func (p *AccountOperation) PreCheck() bool

type AccountOperationID added in v0.0.2

type AccountOperationID ID

type AccountState added in v0.0.2

type AccountState struct {
	AccountID AccountID     `gorm:"unique_index;not null"`           // [FK] Reference to Account table
	State     AccountStatus `gorm:"index;not null;type:varchar(16)"` // AccountStatus [normal, locked, disabled]
}

type AccountStatus added in v0.0.2

type AccountStatus String
const (
	AccountStatusInvalid AccountStatus = ""

	AccountStatusCreated  AccountStatus = "created"
	AccountStatusNormal   AccountStatus = "normal"
	AccountStatusLocked   AccountStatus = "locked"
	AccountStatusDisabled AccountStatus = "disabled"
)

func ParseAccountStatus added in v0.0.2

func ParseAccountStatus(str string) AccountStatus

func (AccountStatus) String added in v0.0.2

func (p AccountStatus) String() string

func (AccountStatus) Valid added in v0.0.2

func (p AccountStatus) Valid() bool

type Base58 added in v0.0.2

type Base58 String

type Credential

type Credential struct {
	UserID       UserID `gorm:"unique_index"`
	LoginHash    Base58 `gorm:"size:64;not null;index"`
	PasswordHash Base58 `gorm:"size:64;not null;index"`
	TOTPSecret   String `gorm:"size:64;not null"`
}

type Currency added in v0.0.2

type Currency struct {
	Name      CurrencyName `gorm:"primary_key;type:varchar(16)"` // [PK] Currency
	Available ZeroInt      `gorm:"default:0;not null"`
	Crypto    ZeroInt      `gorm:"default:0;not null"`
	Precision ZeroInt      `gorm:"default:2;not null"`
}

func NewCurrency added in v0.0.2

func NewCurrency(name CurrencyName, available, crypto, precision Int) Currency

func (*Currency) DisplayPrecision added in v0.0.2

func (p *Currency) DisplayPrecision() Int

func (*Currency) IsAvailable added in v0.0.2

func (p *Currency) IsAvailable() bool

func (*Currency) IsCrypto added in v0.0.2

func (p *Currency) IsCrypto() bool

type CurrencyAvailable added in v0.0.2

type CurrencyAvailable ZeroInt

type CurrencyName added in v0.0.2

type CurrencyName String

type CurrencyRate added in v0.0.2

type CurrencyRate struct {
	ID        CurrencyRateID     `gorm:"primary_key"`
	Timestamp time.Time          `gorm:"index;not null;type:timestamp"`
	Source    CurrencyRateSource `gorm:"index;not null;type:varchar(16)"`
	Base      CurrencyName       `gorm:"index;not null;type:varchar(16)"`
	Name      CurrencyName       `gorm:"index;not null;type:varchar(16)"`
	Rate      CurrencyRateValue  `gorm:"not null"`
}

type CurrencyRateID added in v0.0.2

type CurrencyRateID ID

type CurrencyRateSource added in v0.0.2

type CurrencyRateSource String

type CurrencyRateValue added in v0.0.2

type CurrencyRateValue Float

type Float added in v0.0.2

type Float float64

func ToFixedFloat added in v0.0.2

func ToFixedFloat(value Float) Float

type ID added in v0.0.2

type ID uint64

type Int added in v0.0.2

type Int int

type Model

type Model interface{}

type OperationType added in v0.0.2

type OperationType String
const (
	OperationTypeInvalid OperationType = ""

	OperationTypeDeposit    OperationType = "deposit"
	OperationTypeWithdraw   OperationType = "withdraw"
	OperationTypeTransfert  OperationType = "transfert"
	OperationTypeAdjustment OperationType = "adjustment"

	OperationTypeNone  OperationType = "none"
	OperationTypeOther OperationType = "other"
)

func ParseOperationType added in v0.0.2

func ParseOperationType(str string) OperationType

func (OperationType) String added in v0.0.2

func (p OperationType) String() string

func (OperationType) Valid added in v0.0.2

func (p OperationType) Valid() bool

type RefID added in v0.0.2

type RefID ID

type String added in v0.0.2

type String string

type SynchroneousType added in v0.0.2

type SynchroneousType String
const (
	SynchroneousTypeInvalid SynchroneousType = ""

	SynchroneousTypeSync       SynchroneousType = "sync"
	SynchroneousTypeAsyncStart SynchroneousType = "async-start"
	SynchroneousTypeAsyncEnd   SynchroneousType = "async-end"
)

func ParseSynchroneousType added in v0.0.2

func ParseSynchroneousType(str string) SynchroneousType

func (SynchroneousType) String added in v0.0.2

func (p SynchroneousType) String() string

func (SynchroneousType) Valid added in v0.0.2

func (p SynchroneousType) Valid() bool

type User

type User struct {
	ID    UserID    `gorm:"primary_key"`
	Name  UserName  `gorm:"size:64;unique;not null"`
	Email UserEmail `gorm:"size:256;unique;not null"`
}

type UserEmail added in v0.0.2

type UserEmail String

type UserID added in v0.0.2

type UserID ID

type UserName added in v0.0.2

type UserName String

type ZeroFloat added in v0.0.2

type ZeroFloat *Float

type ZeroInt added in v0.0.2

type ZeroInt *Int

Jump to

Keyboard shortcuts

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